2

通知が消えたら、新しいアクティビティを開始するのではなく、バックグラウンドに置かれたアクティビティを復元したいと思います。FLAGSの使用についていくつかの回答を見てきましたが、実装方法がわかりません

contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | INTENT.FLAG_ACTIVITY_SINGLE_TOP);

これをコードのどこに配置しますか?試しましたが、うまくいきませんでした。助けてください!

        ns = Context.NOTIFICATION_SERVICE;
        mNotificationManager = (NotificationManager) getSystemService(ns);
        icon = R.drawable.icon;
        tickerText = "Short Msg";
        when = System.currentTimeMillis();
        notification = new Notification(icon, tickerText, when);
        context = getApplicationContext();
        contentTitle = "MyApp";
        contentText = "Reopen App";
        notification.defaults |= Notification.DEFAULT_SOUND;
        notification.defaults |= Notification.DEFAULT_VIBRATE;
        notificationIntent = new Intent(this, StartTimer.class);
        contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
4

2 に答える 2

3

それを理解し、AndroidマニフェストでアクティビティをSingleTopまたはSingleInstanceに設定し、新しいアクティビティを作成する代わりに、まだアクティブなアクティビティを再度開きます。

于 2010-08-07T02:36:31.680 に答える
1

「singleTop」は特定の条件下でアクティビティの複数のインスタンスを作成する可能性があるため、正解としてマークされた回答は完全には正しくないことに注意してください。

任意の条件でアクティビティのUNIQUEインスタンスを作成することが実際に保証されている起動モードは、「singleTask」「singleInstance」です。

これらの2つのオプションは、タスクのルートとなるアクティビティの唯一のタスクを作成します。ただし、「singleInstance」は他のアクティビティを許可しますが、「singleTask」は許可します。

ソース: http ://developer.android.com/guide/topics/manifest/activity-element.html#lmode

于 2013-03-22T16:35:24.147 に答える