Reputation: 3910
In my app, I have two Activites, A and B. A is the root/launcher Activity, and B is started from a push notification. If the user is in another app, and clicks a push notification for mine, Activity B will be started. When I call finish() on this Activity, I expect the user to be returned to the app they were in before clicking the notification. Instead, they are brought to Activity A, the root Activity.
Is there a way to start an Activity from a notification, and then finish the Activity and return the user to the app they were in previously?
Upvotes: 3
Views: 1702
Reputation: 520
the follow code is ok,i test that.In AndroidManifest.xml
<activity android:name=".A" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden" android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".B" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden" android:label="@string/app_name2" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
from 3rd app,call that:
Intent intent = new Intent();
intent.setClassName("your.app.packge", "your.app.packge.B");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
U can try that in your project.
Upvotes: 1
Reputation: 13541
You could load the notification's Intent with a particular extra that you can use to change the flow of control of the Activities, this could also be used with the current Activity stack to insure the direction.
Upvotes: 0