Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you generate a loading screen in Android?

The problem is I am coming from another Activity, and when I try to go to the new Activity, it just sits on the old one until the new one is displayed, so I am trying to get it to go to the new Activity right away, and then bring up a loading screen while it gets the content. (The content is either coming from a website or an internal database).

I've tried the progressDialog from the Android development site but it doesn't do anything as the Activity finishes loading before showing anything, so by time it shows up, theres nothing to load.

like image 637
Shant82 Avatar asked Nov 03 '11 03:11

Shant82


People also ask

How do you animate a splash screen on Android?

Go to app > java > first package name > right-click > New > Activity > Empty Activity and create another activity and named it as SplashScreen. Edit the activity_splash_screen. xml file and add image, text in the splash screen as per the requirement. Here we are adding an image to the splash screen.

What is a splash screen in Android?

Android Splash Screen is the first screen visible to the user when the application's launched. Splash screen is one of the most vital screens in the application since it's the user's first experience with the application.


1 Answers

First start new activity first and then call the async task file.. this will start new activity when u close old one. in Oncreate of new activity call the asyn task class like below

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
            setContentView(your layout here);
            new GetTask(this).execute();

   }
}

class GetTask extends AsyncTask<Object, Void, String> {
    Context context;

    GetTask(Context context, String userid) {
        this.context = context;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        mDialog = new ProgressDialog(mContext);
        mDialog.setMessage("Please wait...");
        mDialog.show();
    }

    @Override
    protected String doInBackground(Object... params) {
        // here you can get the details from db or web and fetch it..
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);

        mDialog.dismiss();
    }
}
like image 166
deepa Avatar answered Sep 27 '22 17:09

deepa