How to keep activity on Force Close?
Posted
by
SushiRoll
on Stack Overflow
See other posts from Stack Overflow
or by SushiRoll
Published on 2011-02-06T15:03:42Z
Indexed on
2011/02/06
15:25 UTC
Read the original article
Hit count: 257
I have this piece of code that's really prone to errors so I wrapped it with try{}catch statement. I don't want to go back to the previous activity, I just want it to stay on the current activity so that the user can edit whatever is wrong with them.
How do I implement this?
try{
orgi.insertOrThrow(tableName, null, values);
Toast.makeText(this, "You have successfully created a new profile!", 2).show();
gotoProfileList();
Log.e(getClass().getSimpleName(),"Successfully added to database");
}catch(SQLiteException se){
Log.e(getClass().getSimpleName(), "Database connection failed!" + se);
//Stay in this activity...
}finally{
if (orgi != null){
orgi.close();
}
}
Forget it, I was able to solve my own problem by showing up an alertDialog that tells the user about the error. Thanks anyways. :)
try{
orgi.insertOrThrow(tableName, null, values);
Toast.makeText(this, "You have successfully created a new profile!", 2).show();
gotoProfileList();
Log.e(getClass().getSimpleName(),"Successfully added to database");
}catch(SQLiteException se){
Log.e(getClass().getSimpleName(), "Database connection failed!" + se);
displayError();
//stayInThisActivity();
}finally{
if (orgi != null){
orgi.close();
}
public void displayError(){
AlertDialog.Builder error = new AlertDialog.Builder(this);
error.setMessage("That profile name already exists, try another one.").setCancelable(false).setPositiveButton("Yes",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = error.create();
alert.setTitle("Error");
alert.show();
}
© Stack Overflow or respective owner