android - How to add real Loading Screen -


i have android application of pdf file inside. when open application on lower configuration devices (galaxy 2 etc.), takes while load pdf file. tried adding splash screen in application when opening mainactivity.class after splashscreen still taking same time. how can develop real loading screen? should work on top of main activity layer. here codes:

androidmanifest.xml

        <activity             android:name=".splashscreen"             android:label="@string/app_name"             android:theme="@style/apptheme.noactionbar">             <intent-filter>                 <action android:name="android.intent.action.main" />                 <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>         <activity android:name=".mainactivity"></activity>     </application> </manifest> 

splashscreen.class

public class splashscreen extends appcompatactivity {     private gifimageview gifimageview;     private progressbar progressbar;     handler handler;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_splash_screen);          gifimageview=(gifimageview)findviewbyid(r.id.gifview);         progressbar=(progressbar)findviewbyid(r.id.progressbar);         progressbar.setvisibility(progressbar.visible);          try {             inputstream inputstream = getassets().open("loading.gif");             byte[] bytes  = ioutils.tobytearray(inputstream);             gifimageview.setbytes(bytes);             gifimageview.startanimation();         }         catch (ioexception ex)         {         }          new handler().postdelayed(new runnable() {             @override             public void run() {                      intent intent = newintent(splashscreen.this,mainactivity.class);                     splashscreen.this.startactivity(intent);                     splashscreen.this.finish();             }         },12000);     } } 

here codes how can solve problem?

have considered using async task this? can use async task in mainactivity.

for example can following:

class pdfloader extends asynctask<void, void, void> {     protected void onpreexecute (){         super.onpreexecute();        // here can instantiate progressdialog show progress.      }     protected string doinbackground(void...arg0) {         // here can go ahead write reading logic pdf        // if taking time.     }     protected void onprogressupdate(integer...a){         super.onprogressupdate(a);        // may or may not use this. can act progress updated based on        // integer.     }     protected void onpostexecute(string result) {         super.onpostexecute(result);         // here can dismiss progress bar since read been done.     } } 

call in mainactivity:

new pdfloader().execute(); 

i hope helps you. basic structure started. more information here.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -