-2

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(i.e 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. (i.e 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);
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Vishal Patel
  • 554
  • 6
  • 15
  • What have you tried? You won't get cooked code here based on functionality or whatever. – Ritt Mar 22 '16 at 10:03
  • Ever Heard of BackStack? You can make use of that or a simple google search "Finish all activity in android" would do just fine. – Ritt Mar 22 '16 at 10:05
  • Make your home activity `SingleInstance` and Call it again with `Intent` in `onBackPressed()` – MKJParekh Mar 22 '16 at 10:08

1 Answers1

0

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);
Miguel Benitez
  • 2,322
  • 10
  • 22
  • it gives NullPointerException error. i want to kill calling activity and in my case calling activity is system gallery application – Vishal Patel Mar 22 '16 at 10:58
  • i appreciate your help but i want you to read question again because i dont start any intent. it will start when i select images from gallery and select my app from sharing option. so i dont start any intent at all. hope you understand – Vishal Patel Mar 23 '16 at 11:39
  • How are you opening the gallery? – Miguel Benitez Mar 23 '16 at 12:22
  • As usual from launcher. 1) i open gallery 2) select some pictures 3) click on share button and pick my app from the list. BUT now when i press back button i want to kill gallery app and want to exit my app too. – Vishal Patel Mar 23 '16 at 12:24
  • Now I understand what you mind, give a few sec to think in a possible solution. I though you was launching the gallery through an explicit intent and the explicit intent is in your own app. – Miguel Benitez Mar 23 '16 at 12:45
  • Check this link I think It could be helpful http://stackoverflow.com/questions/9804786/how-to-kill-a-3rd-party-application – Miguel Benitez Mar 23 '16 at 13:04