Issue
I am creating a library project which has chat feature, so user has to register his launch activity as parent in order to perform backstacking(navigating back). here is my manifest for sample app..
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ak.messages.ChatActivity"
android:label="@string/app_name"
android:screenOrientation="sensorPortrait"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustResize">
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
and here is how i am trying to navigate back from ChatActivity
@Override
public void onBackPressed() {
Intent intent = NavUtils.getParentActivityIntent(this);
if(intent!=null){
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
// super.onBackPressed();
}
But its always creating a new instance. is there any way to ensure that same MainActivity's Instance gets revoked when user performs back-press?
PS: Chat activity is not directly invoked by MainActivity I have provided with APIs to launch it.
Thank you.
Solution
Finally able to access/launch an activity with the help of intent actions:
@Override
public void onBackPressed() {
Intent intent = NavUtils.getParentActivityIntent(this);
if(intent!=null){
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setAction("android.support.PARENT_ACTIVITY");
startActivity(intent);
}super.onBackPressed();
}
where user can get the action from the intent to handle..
Answered By - Ak-
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.