1. Are you ready for the Galaxy S20? Here is everything we know so far!

keep showing progressdialog on screen rotation

Discussion in 'Android Development' started by Asaak, Jan 29, 2016.

  1. Asaak

    Asaak Lurker
    Thread Starter

    Hi!

    I have an activity where I have to do som background tasks. I am using a observable/subscriber with rxandroid. Just before starting the background task I show a progressdialog and when the job is done I dissmiss it. Problem is, if I rotate the screen, progressdialog dissapear. What I want is to keep showing progressdialog until the background task finishs.

    This is my code:

    Code (Java):
    1. private Subscriber suscriptor;
    2.  
    3. @Override
    4.     public void onCreate(Bundle savedInstanceState) {
    5.         super.onCreate(savedInstanceState);
    6.  
    7.         suscriptor = new Subscriber() {
    8.             @Override
    9.             public void onCompleted() {
    10.                 progressDialog.dismiss();
    11.                 Log.d("SUSCRIPTOR","ON COMPLETE");
    12.             }
    13.  
    14.             @Override
    15.             public void onError(Throwable e) {
    16.                 Log.d("SUSCRIPTOR","ON ERROR");
    17.             }
    18.  
    19.             @Override
    20.             public void onNext(Object o) {
    21.                 Log.d("SUSCRIPTOR","ON NEXT");
    22.             }
    23.         };
    24.  
    25. //at some point when a button is clicked
    26.  
    27. reset_database.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
    28.             @Override
    29.             public boolean onPreferenceClick(Preference preference) {
    30.  
    31.                 ACTION = LOAD_DATA;
    32.                 progressDialog = ProgressDialog.show(getActivity(), getString(R.string.dialog_carga_configuracion_background),getString(R.string.dialog_carga_porfavor_espere), false, false);
    33.  
    34.                 backgroundTask();
    35.                 return true;
    36.  
    37.  
    38.             }
    39.         });
    40.  
    41. private void backgroundTask()
    42.     {
    43.         setRetainInstance(true);
    44.        Observable.create(
    45.                 new Observable.OnSubscribe<String>() {
    46.                     @Override
    47.                     public void call(Subscriber<? super String> sub) {
    48.                         accionBackground();
    49.                         try {
    50.                             Thread.sleep(5000);
    51.                         } catch (InterruptedException e) {
    52.                             e.printStackTrace();
    53.                         }
    54.                         sub.onNext("cargar");
    55.                         sub.onCompleted();
    56.  
    57.                     }
    58.  
    59.                     @Override
    60.                     protected void finalize() throws Throwable {
    61.                         super.finalize();
    62.                         Log.d("OBSERAVBLE","FINALIZADO");
    63.                     }
    64.                 })
    65.         .observeOn(AndroidSchedulers.mainThread())
    66.         .subscribeOn(Schedulers.newThread())
    67.                .cache()
    68.         .subscribe(suscriptor);
    69.  
    70. @Override
    71. public void onDestroy()
    72. {
    73.     if(suscriptor!=null)
    74.     {
    75.         if(!suscriptor.isUnsubscribed())
    76.         {
    77.             suscriptor.unsubscribe();
    78.         }
    79.     }
    80.  
    81.     super.onDestroy();
    82. }
    83.  
    84. When I rotate screen is not crashing but I am not sure it is finishing job completely.
    85.  
    86. Any ideas how to do what I want?
    87.  
    88. Thanks!
    89.  
    90.  
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - keep showing progressdialog
  1. Kosarar
    Replies:
    5
    Views:
    330
  2. ProfessorD
    Replies:
    3
    Views:
    372
  3. alepabrahao
    Replies:
    1
    Views:
    489
  4. metroidRoid2
    Replies:
    6
    Views:
    793
  5. alexhob123
    Replies:
    12
    Views:
    570
  6. Przemo_c
    Replies:
    5
    Views:
    416
  7. Jeff Leppard
    Replies:
    3
    Views:
    913
  8. R1775
    Replies:
    4
    Views:
    995
  9. The_Chief
    Replies:
    30
    Views:
    2,615
  10. persistentone
    Replies:
    9
    Views:
    1,303

Share This Page

Loading...