Tôi thấy một số cách tiếp cận và tôi đã cố gắng tất cả mọi thứ nhưng couldnt làm cho nó work.I không biết lý do tại sao nó là quá phức tạp, trong các tài liệu có vẻ dễ dàng như vậy! Tôi muốn kích hoạt OnNewIntent với một thông báo (người dùng nhấp vào nó trong thanh thông báo).Android OnNewIntent không được gọi
Hiện nay tôi đã thiết Hoạt động của tôi như singleTop
<activity
android:name="-.-.-.MainMenuActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
</activity>
Đây là mã mà tôi tạo ra các thông báo:
public void showNotification(String text, String componentId){
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logo)
.setContentTitle("Title")
.setAutoCancel(true)
.setContentText(text);
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, MainMenuActivity.class);
if(!componentId.equalsIgnoreCase("")){
resultIntent.putExtra("componentId", componentId);
}
resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, 0);
mBuilder.setFullScreenIntent(resultPendingIntent, false);
mBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify(0, mBuilder.build());
}
Đây là phương pháp OnNewIntent trong MainMenuActivity tôi:
@Override
protected void onNewIntent(Intent intent) {
// TODO Auto-generated method stub
super.onNewIntent(intent);
setIntent(intent);
...
}
Tôi chưa bao giờ nhận được cuộc gọi OnNewIntent. Tôi không biết mình đang làm gì sai. Tôi chỉ sử dụng 2 hoạt động trong toàn bộ ứng dụng và MainMenuActivity xuất hiện sau LoginActivity nên MainMenuActivity luôn luôn nằm trên đầu stack (tôi có nhiều mảnh hơn khi thay thế chúng bên trong MainMenuActivity).
Bất kỳ trợ giúp sẽ được đánh giá cao! Cảm ơn các bạn.
bạn đã bao giờ nhận được bất cứ nơi nào với điều này? Tôi đang ở trong tình trạng tương tự. – Piwaf