I have a problem with FLAG_ACTIVITY_CLEAR_TOP. When the user launches the application, a screen for logging in or registering appears. As soon as the user enters the application, I want all previous actions to close. When I click the back button, it logs in the user and returns it to the LAUNCHER action.
Below is my login. Activity:
public class login extends AsyncTask<String, String, String>{
String email;
String password;
UserFunctions userFunction;
JSONObject json;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(LoginActivity.this);
pDialog.setMessage("Logging into Thryfting...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
publishProgress();
email = inputEmail.getText().toString();
password = inputPassword.getText().toString();
userFunction = new UserFunctions();
json = userFunction.loginUser(email, password);
try {
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
DatabaseHandler db = new DatabaseHandler(getApplicationContext());
JSONObject json_user = json.getJSONObject("user");
userFunction.logoutUser(getApplicationContext());
db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_EMAIL), json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
pDialog.dismiss();
email = inputEmail.getText().toString();
password = inputPassword.getText().toString();
userFunction = new UserFunctions();
json = userFunction.loginUser(email, password);
try {
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
Intent dashboard = new Intent(getApplicationContext(), Timeline.class);
dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(dashboard);
finish();
}
else{
Toast.makeText(getApplicationContext(), "Wrong Email and password combination", Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
source
share