1

I really having stuff with the Activity launch after press on home key.Suppose i have three A, B, C activity and i disable the back press on device. Suppose A is my main Launcher Activity and i move from A to B and B to C and pressed the home key and again click on icon then it always start A that is the launcher. But i did not want like that when press home key on C then click on icon should always start with C Activity. If i press home key on B Activity then always want to open B actvity on click of icon. How to make this.

And one more thing i do not understand about the at the time installation complete it have two option DONE and OPEN. So when press on Done it work fine on keypress with home with the current Activity but when start with OPEN then it always start the A Activity that launcher one on click on icon after press home key at any Current Actvity.

How to resolve this? thanks guys

Manifest.xml file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sunil.apiv2map"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.sendmyposition.A"
            android:configChanges="orientation|keyboardHidden|screenSize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.sendmyposition.B"
            android:configChanges="orientation|keyboardHidden|screenSize" >
        </activity>
        <activity
            android:name="com.example.sendmyposition.C"
            android:configChanges="orientation|keyboardHidden|screenSize" >
        </activity>
    </application>

</manifest>

call actvity A to B

   Intent intent = new Intent(A.this, B.class)
            startActivity(intent);
finish()

and calling B to C

Intent intent = new Intent(B.this, C.class)
            startActivity(intent);
Plo_Koon
  • 2,953
  • 3
  • 34
  • 41
Sunil Kumar
  • 7,086
  • 4
  • 32
  • 50
  • Do you use "singleinstance" or "singletask" launch modes in your app ? if yes, it causes that your main activty, in your case A activity, will be allways brought to the top of activities. – Palejandro Dec 28 '13 at 11:28
  • it does not work in any case – Sunil Kumar Dec 28 '13 at 13:11
  • do you call finish in your B or C activity ?, and that second thing you mentioned, if you click "open" after installation, it opened one instance of your app, and then when you open activity via launcher icon, it opens different instance of your app.. show your manifest file, and some code, maybe it is something in your code.. – Palejandro Dec 28 '13 at 13:44
  • what happened if call finish in B and C and what happened if not call finish in B and C – Sunil Kumar Dec 28 '13 at 13:49
  • if you call finish, that activity, for example B, will be killed/ended, so when you open your app, A activity will show up, because B was already killed. If you not use finish, your activity should be brought to the front. – Palejandro Dec 28 '13 at 13:55
  • and also i am not using "singleinstance" or "singletask" in launcher activity and see i added the manifest file – Sunil Kumar Dec 28 '13 at 13:57
  • in B I am calling finish but in C i did not call finish but C also not comes when click on home press and click on icon open only A not C why? – Sunil Kumar Dec 28 '13 at 14:00
  • manifest looks ok, can you show some code, f.e. how you start your C activity from B activity? Also, your app can be killed when memory is low, are you sure your app is still in memory, when you press home button ? – Palejandro Dec 28 '13 at 14:07
  • yes have alot memory space, but in C i have not finish but why not comes C also when press home key on C – Sunil Kumar Dec 28 '13 at 14:13

1 Answers1

1

You can use Preferences to do this... Package android.preference provides classes that manage application preferences and implement the preferences UI. Using these ensures that all the preferences within each application are maintained in the same manner and the user experience is consistent with that of the system and other applications.

You can save current Activity name (String) in SharedPreferences, and than read this String in MainActivity after application launch to open last opened activity.

Look jukas answer here: How to start another Activity as main and launcher after Deploying the application into device

Or You can use this PoC from here: How to return to the latest launched activity when re-launching application after pressing HOME?

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { 
        // Activity was brought to front and not created, 
        // Thus finishing this will get us to the last viewed activity 
        finish(); 
        return; 
    } 

    // Regular activity creation code... 
} 
Community
  • 1
  • 1
Plo_Koon
  • 2,953
  • 3
  • 34
  • 41
  • how can we launch the open last activity in side the Laucnher activity suppose my launcher activity is MainActivity then how to open the last open activity inside the MainActivity, can you give me the peace of code that need to write in mainactivty – Sunil Kumar Dec 28 '13 at 14:48