Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android activity-reset after picture taken (orientation?)

Well basically, I press a button, this opens up your default camera app by using the camera intent. After a picture is taken, it will save the things needed and redirect to another activity.

In this activity, I have an AsyncTask that can succesfully upload pictures. So what is my problem you may ask. My problem is that it re-creates my activity and therefore reset my ProgressDialog together with it. ( It runs the activity, does the aSyncTask, dies before it can finish it and re-creates my Activity to do the asynctask once again. )

It does not always do this. I think it does this because it changes the Orientation from the phone from Landscape to Portrait. ( I have a Samsung. When I go to the Camera it changes to landscape and when I finish it, it goes back to portrait. )

I've already done my homework and added these things to my manifest:

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

I've made sure to "lock" my app in the portrait orientation but I still see my app change orientation and I believe this is why my activity gets re-created.

I was planning to add all kinds of checks but I believe this is not the right way to handle this situation, since it sometimes does not re-create the activity.

The check I am talking about is to use:

protected void onSaveInstanceState(Bundle outState) {
    outState.putString("started", "1");
}

Anyway, can somebody help me out? I just want it to load the activity without it self-destructing on me.

PS: The VM doesn't have any problems. The VM loads the activity and finishes it without re-creating it.

PPS: Did extra testing, on my Samsung if I keep it on landscape-mode it will work. So it is definately the camera that is destroying my activity with it's orientation change.

like image 671
Yihka Avatar asked Jun 07 '12 12:06

Yihka


2 Answers

I had the same issue, turns out you also need to listen for screen size changes in API level 13 or higher as explained here; https://stackoverflow.com/a/11483806

android:configChanges="orientation|screenSize"
like image 113
Håkon Avatar answered Oct 22 '22 13:10

Håkon


For this to fix, I had to use following in my manifest file:

android:screenOrientation="portrait"    
android:launchMode="singleTop"    
android:configChanges="keyboardHidden|orientation|screenSize"
like image 43
Kailash Gajara Avatar answered Oct 22 '22 13:10

Kailash Gajara