0

What i am doing:: I am trying to bring the functionality of a home button in some other button onclick


  1. I know when we press home button in android app exits !

So Some function is invoked in android to perform this functionality


  • Now i have a Button

button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {


    }

});
  • I need to do onclick of this button i need to call this function
  • How can i do this ?

2 Answers2

0

Add this code in your method:

button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
    Intent startMain = new Intent(Intent.ACTION_MAIN);
    startMain.addCategory(Intent.CATEGORY_HOME);
    startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(startMain);
    }
});
Manish Dubey
  • 4,206
  • 8
  • 36
  • 65
0
button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View arg0) {
            Intent homeIntent = new Intent(Intent.ACTION_MAIN);
            homeIntent.addCategory(Intent.CATEGORY_HOME);
            homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(homeIntent);

    }

});           
Swayam
  • 16,294
  • 14
  • 64
  • 102