Android activity - reset after taking a picture (orientation?)

Basically, I press a button, this opens your default camera application using the camera’s intent. After the picture is taken, it will save the necessary things and redirect them to another activity.

In this exercise, I have AsyncTask that can successfully upload images. So what is my problem, you may ask. My problem is that it recreates my activity and therefore reset my ProgressDialog along with it. (He launches the action, makes aSyncTask, dies before he can finish it, and again creates my activity in order to perform the synthesis again.)

It is not always so. I think he does this because he changes the orientation from the phone from Landscape to Portrait. (I have a Samsung. When I go to the camera, it changes to a landscape, and when I finish it, it returns to the portrait.)

I already did my homework and added these things to my manifest:

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

I made sure to “block” the application in portrait orientation, but I still see the orientation to change my application, and I believe that is why my activity is recreated again.

I planned to add all kinds of checks, but I think that this is the wrong way to handle this situation, because sometimes it does not recreate activity.

The check I'm talking about is to use:

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

Anyway, can someone help me? I just want it to load activity without its self-destruction.

PS: VM . VM , .

PPS: Samsung, , . , , .

+5
3

: , API 13 , ; fooobar.com/questions/82408/...

android:configChanges="orientation|screenSize"
+8

, :

android:screenOrientation="portrait"    
android:launchMode="singleTop"    
android:configChanges="keyboardHidden|orientation|screenSize"
+1

,

"setRetainInstance (true)"; , , /.

, , . , doInBackground() AsyncTask. (.. ), .

:

public class MyFragment extends FragmentActivity {

    private ProgressBar mProgressBar;
    private boolean mAsyncTaskActive = false;


    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        setRetainInstance(true);

        // grab reference to progress bar
        mProgressBar = (ProgressBar) getActivity().findViewById(R.id.my_progress_bar);


        // check to see if the async task is active and set the progress bar visibility accordingly
        if (mAsyncTaskActive) {
            mProgressBar.setVisibility(View.VISIBLE);
            mProgressBarText.setVisibility(View.VISIBLE);
        }


    }

    // this method is called from your main activity when the user does something (i.e. clicks a button)
    // make sure you have already instantiated the fragment

    public void startSomething() {
        if (mAsyncTaskActive == false) {
            mProgressBar.setVisibility(View.VISIBLE);
            new MyAsyncTask().execute();
            mAsyncTaskActive = true;
        }
    }

    private class MyAsyncTask extends AsyncTask<Void, Void, Void> {
        Context applicationContext;



        @Override
        protected Void doInBackground(String... params) {
            // do stuff
            publishProgress(//some number);
            return null;
        }

        @Override
        protected void onProgressUpdate(Integer... progress) {
         setProgressPercent(progress[0]);
        }



}

, , . Android dev DialogFragments, . http://android-developers.blogspot.com/2012/05/using-dialogfragments.html

0

All Articles