React-native: Android app will restart when I back to desktop and click the app icon

Created on 5 Jul 2016  路  13Comments  路  Source: facebook/react-native

Hi!
I use the react-native 0.28.0 Android int the Mac,the problem will be appear when I release the android app and install the phone .When I was operating app for some time, back to the desktop to click on the app icon, app will be re opened and back to the first page of app. I do not know whether the react-native or the other class libraries cause this problem. This is my pakage.json:

 {
 "name": "FasApp",
  "version": "0.0.1",'
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "dev": "JS_DIR=`pwd`; cd node_modules/react-native; npm run start -- --root $JS_DIR  --reset-cache",
    "release": "rm -rf $TMPDIR/react-*; rm ios/main.jsbundle; react-native bundle --platform ios --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle --assets-dest ios/",
    "test": "jest"
  },
  "dependencies": {
    "backo2": "^1.0.2",
    "co": "^4.6.0",
    "component-bind": "^1.0.0",
    "component-emitter": "^1.2.1",
    "dateformat": "^1.0.12",
    "events": "^1.1.0",
    "flux": "^2.1.1",
    "indexof": "0.0.1",
    "json-stringify-safe": "^5.0.1",
    "keymirror": "^0.1.1",
    "lodash": "^4.13.1",
    "moment": "^2.13.0",
    "mx-artifacts": "^0.2.2",
    "numeral": "^1.5.3",
    "qs": "^6.2.0",
    "react": "^15.1.0",
    "react-addons-pure-render-mixin": "^15.1.0",
    "react-native": "^0.28.0",
    "react-native-alphabetlistview": "^0.2.0",
    "react-native-device-info": "^0.9.3",
    "react-native-dismiss-keyboard": "^1.0.0",
    "react-native-extra-dimensions-android": "^0.17.0",
    "react-native-fs": "^1.5.1",
    "react-native-invertible-scroll-view": "^1.0.0",
    "react-native-qiniu": "^0.1.0",
    "react-native-share": "^1.0.11",
    "react-native-swipeout": "^2.0.12",
    "react-native-vector-icons": "^2.0.3",
    "react-native-viewpager": "^0.2.11",
    "react-timer-mixin": "^0.13.3",
    "realm": "^0.13.2"
  },
  "devDependencies": {
    "jest-cli": "^0.9.2"
  },
  "jest": {
    "rootDir": "./",
    "scriptPreprocessor": "<rootDir>/node_modules/react-native/jestSupport/preprocessor.js",
    "setupEnvScriptFile": "<rootDir>/node_modules/react-native/jestSupport/env.js",
    "testPathIgnorePatterns": [
      "/node_modules/",
      "packager/react-packager/src/Activity/"
    ],
    "testFileExtensions": [
      "js"
    ],
    "unmockedModulePathPatterns": [
      "promise",
      "source-map"
    ]
  }
}

Locked

Most helpful comment

There's in an option "don't keep activities" in developer-options of your phone. Did you enable that?

All 13 comments

Are you using a low memory Android phone?

There's in an option "don't keep activities" in developer-options of your phone. Did you enable that?

@satya164 i m using a sony z5 premium and i m having the same issue. i verified @fab1an option and it disabled.

Could it be related to AppState handling ?

@vison123 could you please paste your index.android.js ?

@vison123 do you make use of BackAndroid component ? if not its normal you app restart everytime, cause it kill the app if you use backbutton

I have the same issues =\

@vison123 @Rpaixao you have to remove you listener when you leave the component overwise it ll be executed twice and more ( depending on how much listener you add )

see https://github.com/facebook/react-native/issues/4736

This is happening in this app too:

https://github.com/discourse/DiscourseMobile

I found the next issue related to this thread:

Happening in my project v0.29, but i just tested init a new on v0.33 and it's behaving the same way.

When the app is running, press on the home button of the device/simulator and open the app by clicking on the desktop icon, what happens here is that the app restarts mounting the component again without have unmounted it before, resulting in several instances of the app running if you do this many times.

screen shot 2016-09-23 at 00 13 22

Then, if you press the device back button it will kill and so unmount the top instance letting you with the previous one until the last is unmounted and it will go to desktop.

screen shot 2016-09-23 at 00 15 49

After this if you exit the app as you did initially pressing on the home button and open it by clicking on the desktop icon, this won't restart the app mounting it again, behaving from this moment correctly.
In the same way, if once the app first starts you exit it using the back button, afterwards the home button will behave right.

I don't know anything about android, but what is happening when the app is killed that after this if you send the app to the background using home button it works properly?

Also in the same manner, If you implement a package like react-native-activity-android to avoid kill the app when the back button is pressed, you will end up with multiple apps running.

screen shot 2016-09-23 at 01 34 01

screen shot 2016-09-23 at 01 34 23

should this be a new issue?@satya164

screen shot 2016-09-23 at 18 29 21

Something like this makes the trick, but I also would need to hook in home button press in case you exit the app first pressing this button

Is this somehow related to https://github.com/facebook/react-native/issues/7079?
I have similar problem as https://github.com/facebook/react-native/issues/8570#issuecomment-249070558 when:

  1. Starting my app from "Launch" button in play store
  2. Then launch the app from launcher
  3. Then launch the app from play store
  4. ???
  5. I ended with a stack of ReactActivity

I believe (1) opens the app using Deep link via intent but then again it would be nice if someone that's well-versed in Android comment on this..

Edit: In the end we'll just going to use launchMode="singleTask" as https://github.com/facebook/react-native/issues/7079 suggested since it fits our use case atm

It seems like since there is a reasonable workaround we can close this issue now. Thanks folks for chipping in figuring out what to do here.

Was this page helpful?
0 / 5 - 0 ratings