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
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