Reputation: 1402
This is a way to close an application using a button:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
System.exit(0);
}
});
}
Instead using a button, how can i create a quit item menu? Thanks
Upvotes: 0
Views: 8337
Reputation: 11
Best way to close you're application using click count by pressing back button you can use click count by pressing two times and use
activity.finish();
System.exit(0);
Upvotes: 1
Reputation: 1
Try this after the menu thing:
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(1);
This will kill your com.myapp.activity process
Upvotes: 0
Reputation: 18877
Use methode onOptionsItemSelected(...)
@Override
public boolean onCreateOptionsMenu(Menu menu) {
...
}
@Override
public boolean onOptionsItemSelected(MenuItem Item) {
...
}
see: http://developer.android.com/guide/topics/ui/menus.html
Upvotes: 4
Reputation: 301
You can add menu in action bar by defining it in a menu.xml and can detect on click on that menu using onOptionsItemSelected and can create menu using onCreateOptionsMenu method and Here is the very good tutorial for this -: http://www.vogella.com/articles/AndroidActionBar/article.html
Upvotes: 1