5

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

Community
  • 1
  • 1
Hanry
  • 5,481
  • 2
  • 40
  • 53
  • 1
    There is a long-standing bug in Android regarding a combination of FLAG_ACTIVITY_REORDER_TO_FRONT and translucent theme. It does not work as it should. See http://stackoverflow.com/questions/9309479/bug-theme-translucent-flag-activity-reorder-to-front – David Wasser Sep 30 '14 at 07:36

2 Answers2

2

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.

MKJParekh
  • 34,073
  • 11
  • 87
  • 98
  • I want HOME to be always base activity not to bring it to front, as from HOME only you can leave application. – Hanry Mar 14 '13 at 10:26
  • In Home Activity, write onBackPressed Event, and call Phone's Home Screen http://stackoverflow.com/questions/8515990/call-the-default-home-screen-from-application @hanry – MKJParekh Mar 14 '13 at 11:08
  • If there is custom launcher installed (GoLauncher) it will always ask for home to be selected on back pressed if default launcher is not selected – Hanry Mar 14 '13 at 12:01
  • Try with `exit(0)` instead calling home screen intent, I have not checked.. so test it if it works for your issue @hanry – MKJParekh Mar 14 '13 at 12:26
  • You may use this code to go to the default launcher screen directly : http://pastebin.com/Fz6rLkwy @hanry – MKJParekh Mar 14 '13 at 13:15
0

in your manifest give

android:launchMode="singleinstance";
Jai Kumar
  • 920
  • 1
  • 7
  • 14