java - Splash Screen with AsyncTask -


i want implement splash screen app. did this. @ moment waits 3 seconds , calls mainactivity class. problem have data load , current setup user have waits 2 times. want splash screen loads data. have mainactivity class happens , have splashscreen class.

the method want run in background in mainclass. have splash screen class that

public class splashscreenactivity extends asynctask<void, void, void> {  @override protected void doinbackground(void... params) {     // todo auto-generated method stub     return null; }  protected void onpostexecute(void... params) {     // todo auto-generated method stub  }  protected void oncancelled() {     // todo auto-generated method stub }  } 

i implemented not copied imports , packages, shouldn't problem. now, if understood correctly need write task should done doinbackground method. have call method other activity class, right?

public mainactivity ma = new mainactivity(); 

and in method write ma.parsexmlfromurl();

and afterwards start intent of main class onpostexecute-method this?

protected void onpostexecute(void... params) {     intent mainclass = new intent(splashscreenactivity.this, mainactivity.class);     startactivity(mainclass);  } 

if more information needed gladly elaborate further.

updates

well, after comments tried bit differently.

this oncreate method

    public void oncreate(bundle savedinstancestate) {     strictmode.setthreadpolicy(policy);     super.oncreate(savedinstancestate);     sv      = new scrollview(this);     layout = new linearlayout(this);     layout.setorientation(linearlayout.vertical);     sv.addview(layout);     setcontentview(sv);           new splashscreenactivity().execute("url file"); } 

and splashscreenactivity

public class splashscreenactivity extends asynctask<string, void, void> { public mainactivity ma = new mainactivity();  protected void onpostexecute(void... params) { }  protected void oncancelled() {     // todo auto-generated method stub }  @override protected void doinbackground(string... params) {     ma.parsexmlfromurl(params);     return null; } 

}

but returns blank screen. if call parsexmlfromurl in main activity works fine.

@raghunandan said in comments wrongly created instance of class. glad if elaborate answer.

update number two

current splashscreen-code following:

package de.activevalue.t1000flies;

import android.app.activity; import android.content.intent; import android.os.asynctask; import android.os.bundle;  public class splashscreenactivity extends activity{  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.splash_screen);      new mtask().execute(); }  private class mtask extends asynctask<void, void, void>{      mainactivity ma = new mainactivity();     @override     protected void doinbackground(void... arg0) {         ma.parsexml();         return null;     }      protected void onpostexecute(void... params){         intent = new intent(splashscreenactivity.this, mainactivity.class);         startactivity(i);         finish();     }   } 

}

with code app stucks @ splash-screen. seeems there problem xml-parsing. here xml-parsing-code. note works without problems, when start main activity wihtout splash screen

update number three

i started debug making breakpoints line per line. jumps out @ line

rankingdate [k]             = new textview(this); 

rest of code

for(int k = 0; k < metalist.getlength(); k++){              node metanode = metalist.item(k);             system.out.println(metalist.getlength());             rankingdate [k]             = new textview(this);             rdate       [k]             = new textview(this);             numberoe    [k]             = new textview(this);              element metaelement = (element) metanode;             nodelist rankingdatelist    = metaelement.getelementsbytagname("date");             element rankingdateelement  = (element) rankingdatelist.item(0);             rankingdatelist             = rankingdateelement.getchildnodes();             rankingdate [k].settext("rankingdate: " + ((node) rankingdatelist.item(0)).getnodevalue());             layout.addview(rankingdate[k]);              xmlserializer.starttag(null, "date");             xmlserializer.text(((node) rankingdatelist.item(0)).getnodevalue());             xmlserializer.endtag(null, "date");          } 

the system.out.println gives me 1. , k 0. why null pointer exception?

you should create new activity splashscreen --> splashscreenactivity extends activity, declare in manifest , set layout ;

public splashscreenactivity extends activity{   protected void oncreate(bundle ...){   super.oncreate(...);   setcontentview(...);   new mtask().execute();  }   private class mtask extends asynctask<void, void, void>{  @override protected void doinbackground(void... params) {     // todo auto-generated method stub     return null; }  protected void onpostexecute(void... params) {    intent mainclass = new intent(splashscreenactivity.this, mainactivity.class);     startactivity(mainclass);     finish(); }   }  } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -