Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My application has three activities say A -> B-> C.

Activity A is called from another activity through startActivityForResult(). Activity B and C are also called similarly. I have to call activity A from notifications bar also (if there is some specific notification).

Now, if currently I am in activity B or C, and I click on Notification bar, and call the activity A, the app goes to Activity A only and data entered through activites B or C do not persist.

I don't want such behavior. I want that if I click on Notification, it should redirect to current screen only. Can some one help. (I mentioned activity:launchMode as SingleTask).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
128 views
Welcome To Ask or Share your Answers For Others

1 Answer

Using android:launchMode="singleTask" is probably the best approach, since it won't recreate the activity if it's already running. Just add it to the activity in your AndroidManifest.xml, and you should be all set.

<activity
    android:name=".MyActivity"
    android:label="@string/app_name"
    android:launchMode="singleTask"
    >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
 </activity>

Here's another question that might be useful: Android singleTask or singleInstance launch mode?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...