Android system stops working when starting Media Intent

I launch the intention of the media to take a photo. After the user took the picture and returns to the previous action, the entire application restarts.

Since this does not happen all the time, I think my application goes to the background, android kills it when the device has low memory.

Is there a way to keep my application in the background?

Thank!

+3
source share
5 answers

This is the usual behavior in Android, all actions that are currently not visible on the screen (after onStop) can be killed without notice (i.e. onDestory) if the system has low memory.

, , .

, ( ), .

, onSaveInstanceState savedInstanceState onCreate, (, " pic " ).

+11

...

  • , . , manifest.xml , :

    <   : "nameOfActivity" name=
      android: launchMode = "singleTop" / >

  • , , / .

+2

IMO :

  • onSaveInstanceState/onRestoreInstanceState
  • .
+1

startActivity ()

startActivityForResult(intent, REQUEST_CODE); //private int REQUEST_CODE = 232

, . ,

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
      //Perform your task       
      }
}

follwoing

@Override
    public void onBackPressed() {
        Intent intent = new Intent();
        setResult(REQUEST_CODE, intent);
        super.onBackPressed();
    }

startActivityForResult() - . .

putExtra() getExtra .

, . . , , .

0

R & D . Target Android 4.0, AndroidManifest.xml :

Android: configChanges = "screenLayout | uiMode | orientation | Screen size | smallestScreenSize"

This works for me.

0
source

All Articles