Single copy of activity

In my application, three actions say A -> B-> C

Activity A is called from another activity via startActivityForResult() . Activity B and C are also called similar. I also need to call activity A from the notification bar (if there is a specific notification).

Now, if at the moment I am engaged in activity B or C, and I click on the notification bar and called up by activity A, the application goes only to Activity A, and the data entered through actions B or C is not saved.

I do not want this behavior. I want that by clicking on the notification, it should be redirected only to the current screen. Can anyone help. (I mentioned activity:launchMode as SingleTask ).

+7
source share
2 answers

You can use a static variable to define other data. I am not sure how much or what types of data you want to get from other activities. Nevertheless,

Writing to persistent storage may also work, but again, the uncertainty of what data you store and how difficult it is to answer. Just write / read persistent storage in the onResume and onSuspend each action (or create a Super Activity class and continue it for A, B and C.

0
source

Using android:launchMode="singleTask" is probably the best approach since it will not recreate activity if it is already running. Just add it to the action in your AndroidManifest.xml and everything should be installed.

 <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 startup mode?

+19
source

All Articles