How To Deal with AsyncTask With Screen Orientation

How To Deal with AsyncTask With Screen Orientation

Manage AsyncTask With Screen Orientation Changes? or AsyncTask execute twice when screen orientation chaged?

Manage AsyncTask while screen orientation if you don’t manage then might be¬†AsyncTask called twice when orientation changed

Manage AsyncTask while Screen Orientation changes android.

I’ve follow below seps

STEP 1 – Lock Orientation by calling setRequestedOrientation() method

STEP2 – Once you task over set default orientation that you required

STEP 3 – add android:configChanges=”orientation” in AndroidManifest file

step 1 lock orientation once your task start execution

call lockScreenOrientation() when you task start execution

call unlockScreenOrientation() when your task is complete and you get your desired data

Best Practices in my opinion is create interface

  1. Create Interface
  2. Implement it in Activity
  3. call lockScreenOrientation() before execution of background task
  4. Call interface when you task complete and unlock screen orientation

In my case i need to do file decrypt file and play file so

// STEP 1
public interface DecryptionListener {
public void onDecryption(String path);
}

Thanks & Regards

Imtiyaz Khalani

Sr. Android Developer

Leave a Comment