0

I have a strange issue with my app on 1 phone only so far. I dont have the information on the version of Android on the phone, I just know my colleague tested it on Samsung Galaxy S5 and saw this issue.

When the app is in the background and user tries to open the app from the home screen, the app is not brought back to Front, but it is restarted, from the beginning of the app, instead of the current activity.

I havent been able to test anything, since i dont even know where to start to look for solution of the issue. Also, i cant even test any solution since i dont have the phone.

Any ideas what can be done to force if the app is in the background, to bring it to front and not restart?

EDIT:

here is the onPause method

@Override
public void onPause() {
if(this.hasWindowFocus()) {
        isAudioStopped = true;
        Visibility.activityPaused();
        Intent serviceIntent = TestService.makeStartServiceIntent(this);
        Log.d(TAG,Boolean.toString(background));
        if(basePref.getValue("background", true)){
            startService(serviceIntent);
        }

    }
super.onPause();
}
Borce Ivanovski
  • 561
  • 1
  • 4
  • 23
  • Post the code of the `activity` you want to go back to. You may have put something that kills your activity in the `onPause()` – Pztar Sep 06 '16 at 17:11
  • I have edited my question to include the code. I dont think it is anything in the onPause method, since it is working properly on other phones, just S5 is the issue that i have seen so far, and i think it is running 5.1.1 but i am not 100% sure. – Borce Ivanovski Sep 06 '16 at 17:16
  • It is not guaranteed that your app survives in background. Try to enable ["Don't keep activities"](http://stackoverflow.com/questions/22400859/dont-keep-activities-what-is-it-for) in the dev options and see if that reproduces the issue. – zapl Sep 06 '16 at 17:26
  • @zapl, i just tried that on a tablet running 5.1.1 but still the app is in the background, and when i press the app icon on the home screen, opened up the current activity, at which the app went in the background, didnt started from the beginning as it was the case on S5 – Borce Ivanovski Sep 06 '16 at 20:07
  • And also, this is not happening on any other phone i tested on Note 2,5, S7, Lenovo Tablet, all of them the app is in the background, then if user clicks on the app icon on home page, the app comes to front, does not restart. Can it be issue with the S5 something concrete? the memory usage tested on Lenovo tablet running (5.1.1), shows 15MB, Note 2 running 4.4.2 showing >40MB, but i assume that is the difference in the Android version and the handling of the memory, i will test tonight the S5 and S7, so maybe i see what the problem is – Borce Ivanovski Sep 06 '16 at 20:18
  • I just found some posts of a known bug regarding this issue, so i will try one of the solutions tonight, and let you know if it worked. – Borce Ivanovski Sep 06 '16 at 20:42

1 Answers1

0

The following solution works,

if (!isTaskRoot()) {
    finish();
    return;
}

when it is put in the starting activity, it solves the problem.

I found it through the link from zapl and further searching.

This solution might help other people with the same problem.

Borce Ivanovski
  • 561
  • 1
  • 4
  • 23