0

I have three Activities (A, B and C). Activity A is used to sign in. After a successful sign in Activity A is starts Activity B and then Activity A is killed (using finish()).

Activity B has a button to start Activity C (Activity B has not been finished). Activity C opens the camera onclick(using the camera intent).

When I am on activity C and I press back, Activity B's onResume() is called.

However, when I am on activity C and I start the camera intent and successfully display the image in Activity C and then press back, Activities B onResume() AND onDestroy() gets called and then somehow Activity A is triggered and I have to sign in again instead of just going back to Activity B.

Activity B and C both have the following attributes in the manifest file:

android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden|screenSize"

Is there any way to avoid this and just stay on Activity B?

Extracts from the Manifest file

        <activity
        android:name=".ActivityA"
        android:configChanges="orientation|screenSize"
        android:label="@string/title_login"
        android:screenOrientation="portrait" />
        <activity
        android:name=".ActivityB"
        android:screenOrientation="portrait"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:theme="@style/Theme.TransparentActionbar" />
        <activity
        android:name=".ActivityC"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.TransparentActionbar" />
archLucifer
  • 389
  • 1
  • 10
  • "then Activity A is killed" -- do you mean that you are calling `finish()`? "Activity C opens the camera onclick(using the camera intent)" -- this does not seem to line up with "when I am on activity B and I start the camera intent". Which of these two activities is using `ACTION_IMAGE_CAPTURE`? If the answer is B, how does the user get to C? – CommonsWare Nov 12 '16 at 22:16
  • Sorry for my bad English. Yes I am calling finish(). Sorry it is supposed to read when I am on Activity C and start the camera intent. I will edit my question now. – archLucifer Nov 12 '16 at 22:19
  • 1
    Temporarily comment out the `ACTION_IMAGE_CAPTURE` work. Have A start B, which starts C. Then press BACK from C. Does B behave as you expect, or do you get the same symptoms? If B behaves correctly now, the issue may be that your process was terminated while the camera app was in the foreground, as that commonly happens with camera apps. Your specific symptoms are not what I would expect, but it may be that you are expecting things to have data (e.g., `static` fields) when they do not. – CommonsWare Nov 12 '16 at 22:23
  • In that case, Activity B behaves correctly. The same issue arises when I start a gallery Intent (using `new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);`) from Activity C and press back. – archLucifer Nov 12 '16 at 22:30
  • Hmmm... it is certainly possible that your process is terminated when a gallery-style app is in the foreground, though I have not heard complaints about that. LogCat shows the process ID as part of its output, so you might add some logging to see whether indeed your process is being terminated. If it is, that at least gives you some clues for further diagnosis of why your app is unhappy when this occurs. – CommonsWare Nov 12 '16 at 22:33
  • My logcat: `11-13 00:42:45.959 29443-29443/za.co.app D/za.co.app.BaseActivity: onCreate: Activity B 11-13 00:42:46.684 29443-29443/za.co.app D/za.co.app.BaseActivity: onResume: Activity B - when i press back without opening the camera or gallery intent 11-13 00:43:33.589 29443-29443/za.co.app D/za.co.app.BaseActivity: onResume: Activity B - when i press back with opening the camera or gallery intent 11-13 00:43:33.841 29443-29443/za.co.app D/za.co.app.BaseActivity: onDestroy: Activity B` – archLucifer Nov 12 '16 at 22:47
  • Well, it would not appear that your process is being terminated, as your process ID (29443) is not changing. I am uncertain why you are getting this behavior when launching a third-party app and then returning to your app. Sorry! – CommonsWare Nov 12 '16 at 22:48
  • @CommonsWare I overrided the onStop() and and onDestroy() in Activity B and I just call super.onStop() and super.onDestroy() respectively and it started to behave as expected. I have no idea why. – archLucifer Nov 14 '16 at 10:40
  • post your manifest please – David Wasser Nov 14 '16 at 13:48
  • @DavidWasser I updated the question. – archLucifer Nov 15 '16 at 05:52
  • do you see any other exceptions or messages in the logcat? Don't filter the logcat in case you filter out something important. Your statement that you override `onStop()` and `onDestroy()` and simply call the `super` methods and that makes it work, makes absolutely no sense at all. What device are you testing on? – David Wasser Nov 15 '16 at 13:39
  • @DavidWasser nothing else in the logcat. Exactly, that's why I am so baffled. I am testing on a sony Z3 compact with marshmallow. It is a test phone with nothing else at all on it. – archLucifer Nov 15 '16 at 17:31

0 Answers0