1

I have a menu button on the bottom and I have display menu icons from another activity like MenuTask.

But how to close that MenuTask activity if the user clicks again in the menu?

imgMenu.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View arg0) {
        if (key == 0) {
            // I want to show menu here
            key = 1;    
            Intent intent = new Intent(MainActivity.this, MenuAction.class);
            startActivityForResult(intent, 2);
            setResult(0);
        } else if (key == 1) {
            // I want to Delete menu here
            key = 0;
            //onBackPressed();
            finish();
        }
    }
});

Note: I think if i click second time , button could not fire. it means else part not execute. enter image description here

Problem: I have Clicked, right top menu button and open new activity menu action. but if i want to click again same menu button, i want to disappers that menu action. but menu button could not clicked.

How to make MenuButton Clickable? any idea? any other menthod? But when i click mobile backbutton menuaction layout disappeared. Thanks in advance.

B B
  • 63
  • 6

2 Answers2

0

I thing this is not best way. You must use Fragment

If you want only kill activity MenuAction.this.finish();

Farid Valiyev
  • 203
  • 5
  • 20
0
@Override
public void onBackPressed() {
  if (doubleBackToExitPressedOnce) {
    super.onBackPressed();
    return;
  }

  this.doubleBackToExitPressedOnce = true;
  Toast.makeText(this, "Please click BACK again to exit", Toast.LENGTH_SHORT).show();

  // handler to delay
  new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
      doubleBackToExitPressedOnce=false;                       
    }
  }, 2000);
} 

you can go though this link Clicking the back button twice to exit an activity

same question

Community
  • 1
  • 1
Abhishek
  • 2,350
  • 2
  • 21
  • 35