I have 3 activities: Home(Base activity) with
<activity
android:launchMode="singleTop"
android:name="com.Home"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Other two activites: Activity1 and Activity2
with theme android:theme="@android:style/Theme.Translucent"
can be called from each other or from home.
They always return to home onBackpress() it is override
intent.setClass(this, Home.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
when activity1 is called from activity2
intent.setClass(this, ACtivity2.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
its onResume is called but cannot be seen Is there any solution?
I want only single instance of Activity in stack.
Requirements: Activity1 and Activity2 should once created should never be destroyed(They should be always called from history) until Home is called.
Help me out. Thanks in Advance.
Visited this too
I assume the problem occurs because you are using FLAG_ACTIVITY_CLEAR_TOP for Home Activity.
As, It performs
If there is already an instance of the called activity type present in the stack, then this instance is brought to the foreground instead of creating a new instance. Also, all activities in the stack that reside on top of that instance are cleared from the stack. For example, assuming that the current activity stack is ABCDE, launching an activity of type C will clear activities D and E from the task and result in the stack ABC.
So your Activity 1 and Activity 2 gets cleared when you call Home Activity.
Solution :
Call Home Activity with FLAG_ACTIVITY_RESET_TASK_IF_NEEDED or FLAG_ACTIVITY_REORDER_TO_FRONT
AS, It performs
This flag has no effect unless the intent creates a new task or brings an existing task to the foreground. In that case, the task is reset, meaning that task affinities are applied (resulting in activities being moved from or to this task) and that, given that FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET is set as well, the task is cleared according that flag’s specification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With