The more I research this, the more confused I get. I admit I'm pretty new to this Android stuff. Maybe someone can explain this to me in the context of my specific issue.
In the Android app, I have a Main Activity. Here's the relevant code from said Activity.
installation.saveInBackground(new SaveCallback() {
public void done(ParseException e) {
if (e == null) {
Log.v("PRBTEST","Successful save of installation");
} else {
Log.v("PRBTEST","Unsuccesfull save of installation: " + e.getMessage());
ParseErrorHandler.handleParseError(e);
}
}
This code is towards the end of the onCreate() function, and is intended to catch an issue with Parse.com, our backend server, where the session token becomes invalid. The error handler is supposed to check the error, and depending on the type of error, do something about it. For now we only have one context, which is the session token error. In response it gives you a popup telling you to login again, and sends you back to the startup screen where you can login.
Here's the error handler class.
public class ParseErrorHandler {
public static void handleParseError(ParseException e) {
switch(e.getMessage()) {
case "invalid session token": handleInvalidSessionToken();
break;
}
}
private static void handleInvalidSessionToken() {
AlertDialog.Builder alert = new AlertDialog.Builder(//...);
alert.setMessage("Oops! Your session is no longer valid. Please sign in again.")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
revertToSignIn();
}
});
alert.create().show();
}
private static void revertToSignIn() {
ParseUser.logOut();
Global.loggedIn = false;
Global.user = ParseUser.getCurrentUser();
Intent intent = new Intent(//..., ActivityStartup.class);
startActivity(intent); //<<this line can't be resolved at the moment
finish(); //<<this line can't be resolved at the moment
}
} A couple issues here. I know I have to pass some kind of context into the methods in ParseErrorHandler so they can be used in the parameters that are currently replaced with //... . Problem is I don't understand for the life of me what these contexts are and how they work and every online explanation gets progressively more abstract. I thought the context was essentially just the Activity that the Intent or AlertDialog is being called from but this must not be correct.
The other issue is that the last couple lines in revertToSignIn() that activate the intent cannot be resolved from ParseErrorHandler. These seem like they should be relatively basic issues but could someone please clearly explain this to me?