Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How add an Application Pre-loader/Startup screen/Splash Screen to My PhoneGap Android App

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.

like image 294
user232751 Avatar asked May 03 '11 06:05

user232751


2 Answers

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).

like image 195
Vinayak Bevinakatti Avatar answered Oct 30 '22 07:10

Vinayak Bevinakatti


You could create an AsyncTask implementation for showing an image / progress indicator while your application's data is loading in the background thread.

  1. In the async task's onPreExecute method you show the chosen preloader (image / ProgressDialog / etc)
  2. in the doInBackground method you start loading the necessary data, and
  3. in the onPostExecute method you remove/hide your preloader, so the activity's desired layout will be shown.
like image 26
rekaszeru Avatar answered Oct 30 '22 06:10

rekaszeru