I am using a custom Alert dialog. If user go with negative button of the code I need the close the app totally. I am using following code.
public class TestApp extends TabActivity {
private int tabid = 0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
Intent myint = this.getIntent();
tabid = myint.getIntExtra("tab_id", 0);
.......................
.........................
.......................
tabHost.setCurrentTab(tabid);
showReward(this);
}
private void showReward(Context c) {
// TODO Auto-generated method stub
final AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = c;
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog, (ViewGroup) findViewById(R.id.layout_root));
TextView text = (TextView) layout.findViewById(R.id.title);
text.setText("Sample text");
text.setGravity(Gravity.CENTER);
TextView msg = (TextView) layout.findViewById(R.id.msg);
msg.setText("Sample text.");
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Log.d(null,"step1");
dialog.cancel();
Log.d(null,"step2");
closeApp();
}
});
alertDialog = builder.create();
alertDialog.show();
}
private void closeApp(){
Log.d(null,"step3");
this.finish();
}
}
But it is working perfectly before to add showReward() function. When u add the function, the dialog box is appearing perfectly. If we click on the negative button it is giving NullpointerException due to “Unable to destroy activity”. Whats the problem with my code?
this is problem related to cursor.close() at the time finish. No such close during finish()