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.
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.
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.
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();
}
}
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