いくつかのアプローチを見て、すべてを試しましたが、うまくいきませんでした。なぜそんなに複雑なのかわかりません。ドキュメントではとても簡単に見えます! 通知で OnNewIntent をトリガーしたい (ユーザーは通知バーでそれをクリックします)。
現在、アクティビティをsingleTopとして設定しています
<activity
android:name="-.-.-.MainMenuActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
</activity>
これは、通知を作成するコードです。
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());
}
これは、私の MainMenuActivity の OnNewIntent メソッドです。
@Override
protected void onNewIntent(Intent intent) {
// TODO Auto-generated method stub
super.onNewIntent(intent);
setIntent(intent);
...
}
OnNewIntent 呼び出しを取得しません。何が間違っているのかわかりません。私はアプリ全体で 2 つのアクティビティのみを使用し、MainMenuActivity は LoginActivity の後に来るため、MainMenuActivity は常にスタックの一番上にある必要があります (MainMenuActivity 内でそれらを置き換えるフラグメントがさらにあります)。
どんな助けでも大歓迎です!君たちありがとう。