You can do something similar in the manifest to allow rotation:
<application android:allowBackup="true" android:configChanges="orientation|keyboardHidden|screenSize" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name=".activities.MainActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name"/>
Then you can catch the rotation with this sniper inside your activity:
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); Log.v(this.getClass().getName(), "onConfigurationChanged()"); }
To perform asintask with the progress dialog box, this sniper should give you the following:
private ProgressDialog pDialog; private class MyAsync extends AsyncTask<String, Void, String> { Activity context; public MyAsync (Activity context) { this.context = context; } @Override protected void onPreExecute(){ super.onPreExecute(); pdia = new ProgressDialog(context); pdia.setMessage("Loading..."); pdia.show(); } @Override protected String doInBackground(String... urls) { ...
And to use this asintask, you call:
new MyAsync(this).execute(null, null , null);
By the way, this is your activity / fragment.
source share