Click the "Clear Activity" button on the home button
There are several actions in my application, the first of which is the login screen, I want it to always force the user to log in even if they stopped the application with the home button and restore it. Is there a way to achieve this in android?
use android:clearTaskOnlaunch="true"
in your activity Launcher in the manifest and for all other activities use android:finishOnTaskLaunch="true"
in the manifest.
For reference, take a look at the link below, it will help you do what you want.
Kill all actions when HOME key pressed android pressed
This is my home listener. Just attach it to your home button and it will clear the stack when you start the home operation: home_button.setOnClickListener( new HomeButtonListener(this) );
where this
is the link to the activity that the home button is in. The name of my home activity is Home.java
inside my own package activities
. Just don't want anyone to be confused about import activities.Home
my use Home.class
.
import activities.Home;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
public class HomeButtonListener implements View.OnClickListener
{
Activity activity;
public HomeButtonListener( Activity activity )
{
this.activity = activity;
}
@Override
public void onClick(View v)
{
Intent intent = new Intent(activity, Home.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
activity.startActivity(intent);
}
}