Manage Splash screen activity and background tasks on android -
i have 2 activities. 1 splash , other main activity loads fragments pages. splash no background tasks, sit pretty , transition main activity following background tasks.
- set admob ads
- request data file server
- decript encryption key
- loads images disk display
- set google leader-board or sign in if user not sigh in.
my question how delegate of these tasks splash screen? , how pass these complex objects between activities (can use static variables)
at moment contemplating ditch splash activity , use main activity show splash image in that. main activity layout has banner adds not sure how cover entire screen image.
please help!
my main activity
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <linearlayout android:id="@+id/fragment" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical" android:layout_above="@+id/fragment_ad"/> <fragment android:id="@+id/fragment_ad" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignparentbottom="true" class="com.controllers.adfragment" /> </relativelayout> public class splashactivity extends activity { /** duration of wait **/ private final int splash_display_length = 2000; string data = ""; /** called when activity first created. */ @override public void oncreate(bundle icicle) { super.oncreate(icicle); this.requestwindowfeature(window.feature_no_title); this.getwindow().setflags(windowmanager.layoutparams.flag_fullscreen, windowmanager.layoutparams.flag_fullscreen); setcontentview(r.layout.splash); data = getintent().getdatastring(); /* new handler start menu-activity * , close splash-screen after seconds.*/ new handler().postdelayed(new runnable(){ @override public void run() { /* create intent start menu-activity. */ intent mainintent = new intent(splashactivity.this,mainactivity.class); if(data != "") mainintent.putextra(utils.challenge_data_code, data); splashactivity.this.startactivity(mainintent); splashactivity.this.finish(); } }, splash_display_length); }
i think should split workload this:
data , work must have before user can use app should executed in splash screen , off-course should wait finish before continuing main activity. don't want let user wait if there's no reason. there few ways can transfer data main activity:
a. use intent extras when possible. if there custom objects, can serialize them using gson example, , deserialize them in main activity.
b. save data in application class/sharedpreferences
you can start getting data need later in splash using thread, don't let user wait when there isn't reason.
Comments
Post a Comment