Monday, September 9, 2013

[android help] onBackPressed method showing for less than a second


onBackPressed method showing for less than a second


android - onBackPressed method showing for less than a second - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
















I am using the above method to create something like an exit dialog for my application. The code works just fine but the alert dialog box only stays on screen for less than a second. Then it dissapears and the application closes without following my instructions. I have no idea why this is happening.


Thank you guyz in advance.



@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();

DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
ganthem.stop();
System.exit(0);
break;

case DialogInterface.BUTTON_NEGATIVE:

dialog.cancel();

break;
}
}
};

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Exit or not ?").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
}




























Remove super.onBackPressed();.




















default






Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...