android - How to execute asynctask in viewpager? -


i have 3 pager views. when try execute asynctask app crashes because task starts simultaneously. want perform asynctask pager visible. how do that?

pager 1:

public class test extends android.support.v4.app.fragment {      private myasynctask mauthtask = null;      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {          view test = inflater.inflate(r.layout.test, container, false);         ((textview)test.findviewbyid(r.id.textview)).settext("test");         return test;     }      @override     public void setuservisiblehint(boolean isvisibletouser) {         super.setuservisiblehint(isvisibletouser);         if (isvisibletouser) {             attemptlogin();         }     }     @override     public void onviewcreated (view view, bundle savedinstancestate) {      }       public void attemptlogin() {          if (mauthtask != null) {             return;         }         mauthtask = new myasynctask();         mauthtask.execute((void) null);     }        private class myasynctask extends asynctask<void, void, void>     {         @override         protected void onpostexecute(void result) {             //mprogressdialog.dismiss();             toast.maketext(getactivity(),                     "completed", toast.length_long).show();         }         @override         protected void onpreexecute() {             toast.maketext(getactivity(),                     "loading explore", toast.length_long).show();         }          @override         protected void doinbackground(void... params) {             // network operation                return null;         }     } } 

try this...

//call/execute asynktask

new myasynctask().execute(); 

// code sample of asyntask

private class myasynctask extends asynctask<void, void, void>     {         jsonobject jobject;         @override         protected void onpreexecute()         {             super.onpreexecute();             //         }          @override         protected void doinbackground(void... arg0)         {      // doing bakground task        return null;         }       protected void onpostexecute(void result)         {         super.onpostexecute(result);        }    } 

Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -