Click the "Clear Activity" button on the home button
2 answers
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);
}
}
0
source to share