I have created a Android app using phone Gap.It works fine.How I add a pre-loader image to My App.Now it show a white page while loading the application.
Help is highly appreciated, Thank, VKS.
If you mean pre-loader image has Splash screen refer the following code;
For PhoneGap :
public class MyDefaultActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setIntegerProperty("splashscreen", R.drawable.splash); // Displays the splash screen for android
super.loadUrl("file:///android_asset/www/index.html",3000); // Second parameter is duration for delay of splash screen
}
}
For Android Native app :
public class MySplashScreen extends Activity {
private CountDownTimer lTimer;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.splashscreen); // Contains only an LinearLayout with backround as image drawable
lTimer = new CountDownTimer(5000, 1000) {
public void onFinish() {
closeScreen();
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
}
}.start();
}
private void closeScreen() {
Intent lIntent = new Intent();
lIntent.setClass(this, MyLauncherActivity.class);
startActivity(lIntent);
finish();
}
}
Make sure a file called splash.png
is present as res/drawable-hdpi/splash.png
(RGBA).
You could create an AsyncTask
implementation for showing an image / progress indicator while your application's data is loading in the background thread.
onPreExecute
method you show the chosen preloader
(image / ProgressDialog / etc)doInBackground
method you
start loading the necessary data,
andonPostExecute
method you
remove/hide your preloader, so the
activity's desired layout will be
shown.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With