Reputation: 672
Each time my app icon from home screen is clicked, I want the app to start my FirstActivity.java
. The problem now is, say I have navigated through my app and is in the ThirdActivity.java
and I have clicked the home Button
and go to check out my other apps. Again when I click the app icon in home screen, my Application
starts from ThirdActivity.java
. I want it to start from FirstActivity.java
.
I have used clearTaskOnLaunch="true"
in manifest for my FirstActivity.java
and also checked using android:finishOnTaskLaunch ="true"
in all my other activities but the problem is still there. How can I solve this?
Upvotes: 2
Views: 3928
Reputation: 287
I had resolved the issue by adding all three tags android:launchMode="singleTask" android:clearTaskOnLaunch="true" android:finishOnTaskLaunch ="true" in manifest splash screen activity may be helped some one:
<activity
android:name=".SplashscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:launchMode="singleTask"
android:clearTaskOnLaunch="true"
android:finishOnTaskLaunch ="true"
android:screenOrientation="portrait"
android:theme="@style/AppThemeForAppCompact">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Upvotes: 0
Reputation: 1959
You can use moveTaskToBack(true)
when you click on the homebutton and start the activity you want to.
Upvotes: 0
Reputation: 958
All I have to do was declare android:launchMode="singleTask" in manifest for my FirstActivity.java "only". By doing this, every time user selects the app by clicking the app icon in the home screen, app will start with FirstActivity.java
Say the user has navigated through my app and is in the ThirdActivity.java and clicked the home Button. The user has the option of selecting the app again from the background apps section (task manager section). If he/she does so, it will start from where he/she has left (ThirdActivity.java). Only if they click the app icon will the app start from FirstActivity.java
Upvotes: 3
Reputation: 8058
You can use this code in onPause()
of the second third activity but you have to take care of if onPause()
is called because of clicking home button or by any other mean, Code is:
Intent intent = new Intent(AnyActivity.this,FirstActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
Upvotes: 0
Reputation: 321
In your oncreate you just have to start your activity using Intent
In manifest you have to provide name attribute to application tag
<application
android:allowBackup="true"
android:icon="@drawable/app_logo"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:name=".class name which extends Application"
>
Here you can see details on how to use application class: http://www.intertech.com/Blog/androids-application-class/
http://developer.android.com/reference/android/app/Application.html
Upvotes: 0
Reputation: 514
you need to finish you current activity at the time when you are launching intent for new activity, there is a method to do that finish();
Upvotes: 0