i want to make android apps which is the apps will destroy when home is tapping. so when app started again the apps will relaunching again from beginning. Not resume apps``
4 Answers
@Override
public void onAttachedToWindow()
{
Log.i("TESTE", "onAttachedToWindow");
this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD);
super.onAttachedToWindow();
}
With this method, the HOME Button stops working in this activity (only this activity). Then you just reimplement as it was a normal button event (the back button for instance).
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_HOME) {
Log.i("TESTE", "BOTAO HOME");
return true;
}
return super.onKeyDown(keyCode, event);
}
taken from Can I override the 'Home' button in my application?
You can override the onPause and finish the app everytime the activity is paused. This will destroy the app when not in the foreground.
@Override
public void onPanelClosed(int featureId, Menu menu) {
finish();
super.onPanelClosed(featureId, menu);
}
Or you can say, in the manifest, that this activity should not be able to go back to. This will not destroy the app when not in the foreground.
<activity
android:name="com.testapp.MainActivity"
android:label="@string/app_name"
android:noHistory="true" >
</activity>
- 1,021
- 8
- 14
In the manifest for your main activity put
android:clearTaskOnLaunch="true"
android:finishOnTaskLaunch="true"
From official document for clearTaskOnLaunch http://developer.android.com/guide/topics/manifest/activity-element.html
When the value is "true", every time users start the task again, they are brought to its root activity regardless of what they were last doing in the task and regardless of whether they used the Back or Home button to leave it. When the value is "false", the task may be cleared of activities in some situations (see the alwaysRetainTaskState attribute), but not always.
Suppose, for example, that someone launches activity P from the home screen, and from there goes to activity Q. The user next presses Home, and then returns to activity P. Normally, the user would see activity Q, since that is what they were last doing in P's task. However, if P set this flag to "true", all of the activities on top of it (Q in this case) were removed when the user pressed Home and the task went to the background. So the user sees only P when returning to the task.
- 17,823
- 3
- 48
- 52