5

私はタイマーアプリケーションのように作成しています。タイマーを開始すると、Androidホームに移動するか他のアクティビティを開始するオプションがあります。

タイマーを開始するときに通知バーアイコンを設定し、他のアプリケーションを使用する場合(開始したタイマーアクティビティから移動することを意味します)、通知アイコンをクリックして以前に開始したタイマーアクティビティに戻る必要があります???

クリックすると、以前に開始されたタイマーアクティビティではなく、新しいインスタンスタイマーアクティビティが開始されます。、次に戻るボタンをクリックすると、以前のタイマーアクティビティが表示されます。

質問は次のとおりです。通知バーを介して以前に開始したアクティビティを呼び出す方法、そのアクティビティの新しいインスタンスを開始しない方法??

これは以下の私のコードのサンプルです:

private void notificationBar()
{
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    int icon = R.drawable.ico;
    CharSequence tickerText = "some title...";
    long when = System.currentTimeMillis();

    Notification notification = new Notification(icon, tickerText, when);
    Context context = getApplicationContext();
    CharSequence contentTitle = "some app title";
    CharSequence contentText = "...some info !";
    Intent notificationIntent = new Intent(this, main.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,  PendingIntent.FLAG_UPDATE_CURRENT | Notification.FLAG_AUTO_CANCEL);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);


    mNotificationManager.notify(NOTIF_ID, notification);

}    
private void notificationClose(int notifID)
{
    String ns = Context.NOTIFICATION_SERVICE;
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
    mNotificationManager.cancel(notifID);

}
4

2 に答える 2

14

フラグに関する答えを見つけました: Android:new Intent()はandroid:launchMode="singleTop"で新しいインスタンスを開始します

Intent intent= new Intent(context, YourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
于 2010-11-04T20:31:48.067 に答える
2

私はあなたが何を意味するのか理解できません。

アプリを呼び出すためにどの通知が正確に使用されたかを指定するために、インテントに追加を追加できると思います。これはまったく役に立ちますか?

于 2010-11-03T16:31:43.383 に答える