rookie android dev here. I have a problem with some ProgressDialog in an AsyncTask.
I want to apply a theme when I create a ProgressDialog, but when I apply it, the dialog just go fullscreen and my activity is hidden. When i remove the theme at instantiation, it's normal.
I just want to know why.
Here is my class with the AsyncTask :
public class Synchronize {
private static AppManager app = AppManager.getInstance();
public void Synchronise() {
}
AsyncTask<Void, Void, Boolean> task = new AsyncTask<Void, Void, Boolean>() {
private ProgressDialog pd;
@Override
protected void onPreExecute() {;
pd = new ProgressDialog(app.m_AppContext, android.R.style.Theme_Black);
pd.setTitle("Veulliez patienter");
pd.setMessage("Synchronisation en cours...");
pd.setCancelable(false);
pd.setIndeterminate(true);
pd.show();
}
@Override
protected Boolean doInBackground(Void... arg0) {
try {
//Synchronisation
Thread.sleep(2000);
Log.d("DEBUG","sync en cours");
} catch (InterruptedException e) {
e.printStackTrace();
return false;
}
return true;
}
@Override
protected void onPostExecute(Boolean result) {
pd.dismiss();
if (result)
Toast.makeText(app.m_AppContext, "Synchronisation terminé avec succès", Toast.LENGTH_SHORT).show();
else
Toast.makeText(app.m_AppContext, "La synchronisation a échoué", Toast.LENGTH_SHORT).show();
Log.d("DEBUG","SYNC DONE");
}
};
public void startSync() {
if (app.m_bIsOnline)
task.execute((Void[])null);
else
Toast.makeText(app.m_AppContext, "Mode offline. Synchronisation impossible", Toast.LENGTH_SHORT).show();
}
}
Thanks for help.
You need to change style parent to dialog. For example:
<style name="AppTheme.Light" parent="Theme.AppCompat.Dialog" >
<item name="colorAccent">@color/theme_color</item>
<item name ="android:background">@color/theme_background_light</item>
<item name = "android:textColor">@color/black</item>
</style>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With