I have three fragments in the app. I am creating, call them f1,f2, f3. All these are contained in the MainActivity. In the third fragment f3, I have a button which takes a user to an activity where they can post a picture. Now whenever the post is successful (using onSuccessListener), I am displaying a toast message and thereafter taking the user to the MainActivity using intent.
Everything works fine, but I wanted to take the user to the previous fragment f3, rather than the MainActivity which launches with fragment f1. How can I achieve this?
Here is what I've tried so far:
@Override
public void onBackPressed(){
finish();
}
// didnt work
Here is the current code that am using
//my other code
PostsRef.child(current_user_id + timesfm).updateChildren(postsMap)
.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task)
{
if(task.isSuccessful())
{
Toast.makeText(PostActivity.this, "Post updated.", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
SendUserToMain();
}
else
{
Toast.makeText(PostActivity.this, "Error Occured.Please try again.", Toast.LENGTH_SHORT).show();
loadingBar.dismiss();
}
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
private void SendUserToMain() {
Intent mIntent = new Intent(PostActivity.this, MainActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(mIntent);
}