I have two activities in My application, one being launcher and the other is launched as a explicit call from the first.
Here My problem is when i go back to home sc
Without seeing your code, I think you want something like this answer:
Android finish Activity and start another one
You need to set intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
and you'll also need to finish()
your launcher activity as well.
I use the following code in the LAUNCHER
Activities of my apps to prevent the app from beeing started again when its still alive in the background and the icon is tapped
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!isTaskRoot()) {
finish();
return;
}
// Rest of your onCreate stuff goes here
}
This just finishes the LAUNCHER
Activity and resumes the last used one.
Try using the following code in the onCreate method of the activity that is specified as the Launcher Activity in the Manifest, i.e. the ContentDownload activity from the original code posted in the question:
if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) {
finish();
return;
}
This will finish your Launcher Activity before it is displayed by detecting that there is already a task running, and your app should instead resume to the last visible Activity.
See this page in the Android documentation regarding Android Manifest launchModes: http://developer.android.com/reference/android/R.styleable.html#AndroidManifestActivity_launchMode
Do not call finish(). You need to pass to the Intent the flag FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK.
Intent intent = new Intent(this, ActualAppActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK| Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
You've got both your activities defined with launchMode="singleTask"
. This is the root of your problem. Remove that.
what you can do is store a string in the persistent storage which determines whether the assets have been loaded before or not.
Then, in the main activity, you may check if the assets have been loaded or not and then start the required activity.
if(assets_already_downloaded)
second_activity();
else
download_asset_activity();