i have searched a lot but i cant find answer so i thought i should post here.
problem
my app works on images which are share by gallery application(ie default gallery app) and its works fine. but i want to override OnBackPress() method to check whether back button is pressed or not and if backbutton is pressed then i simply want to get calling activity name and want to kill that activity and go back to home.
i can do this if i call another activity form my activity but how can get calling activity name if it is a system app. (ie gallery application)
keep in mind that my app called when i share images from gallery app so basically i want to get gallery activity to kill it and can go back home safely. i dont wannna go back to gallery app.
i want to simply go back to home and kill that gallery app instead of going back to gallery app.
here is OnBackPressed() method
@Override
public void onBackPressed() {
// do something on back.
// what i tried so far but it is not working
this.getParent().finish();
this.finish();
}
i tired this and hopefully i can go back home safely but still gallery app run in background. i want to kill calling app too.
public void onBackPressed() {
moveTaskToBack(true);
}
Maybe something like this:
this.getParent().finish();
this.finish();
If this is not working you could try to add a filter in your intent before you open this explicit activity:
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.