问题
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);
回答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...
}
来源:https://stackoverflow.com/questions/20813918/how-to-always-open-current-activity-on-icon-press-after-pressing-the-home-key