android - How to implement a loading screen to prevent a user from interacting with the interface while doing background processing -


in new app need show animation while doing processing(e.g sending data server, reading data web service, etc).

something this:

enter image description here

this used when wanted implement similar:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >         <relativelayout         android:id="@+id/sincronizarspinnerlayout"         android:layout_width="match_parent"         android:layout_height="match_parent"         android:visibility="gone" >          <progressbar             android:id="@+id/pbheaderprogress"             style="@android:style/widget.progressbar.inverse"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_centerinparent="true" >         </progressbar>     </relativelayout>       <relativelayout>        <!--main content here-->      </relativelayout>    </linearlayout> 

as can see have 2 nested relative layouts. first layout invisible (android:visibility="gone") default , make visible when start service, asynctask or asynchronous technique.

although have used method in past, main layouts (the ones should go inside second relative layout) more complicated, i'm not sure it'd idea make things more complicated adding nesting level activity.

  1. is there way can avoid having add layout of activities need display spinner animation? perhaps there's kind of pattern or practice i'm not aware of.

  2. do need worry adding nesting level activity, knowing have 2 or 3 levels?

thanks.

you can use progressdialog , use setcanceledontouchoutside(false) user cannot touch outside while asynctask working.

here structure code use in project use asynctask. can apply project:

public class downloadtask extends asynctask<void, void, void> {     private progressdialog mprogressdialog;      private context mcontext;      public downloadtask(context context) {         this.mcontext = context;     }      @override     protected void onpreexecute() {         super.onpreexecute();          mprogressdialog = progressdialog.show(mcontext, "downloading", "downloading data ...");         mprogressdialog.setcanceledontouchoutside(false); // main method force user cannot click outside         mprogressdialog.setcancelable(true);         mprogressdialog.setoncancellistener(new dialoginterface.oncancellistener() {             @override             public void oncancel(dialoginterface dlg) {                 downloadtask.this.cancel(true);             }         });     }      @override     protected void doinbackground(void... params) {         // background work here      }      @override     protected void onpostexecute(void result) {         if (this.iscancelled()) {             result = null;             return;         }          if (mprogressdialog != null) {             mprogressdialog.dismiss();         }      } } 

hope :)


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -