Application Showing Black Screen?
I am implementation an android application. I am using web service on one activity. I am showing a progress dialog until it loads second Activity. But it does not show for whole ti
Solution 1:
for your case use this...
made progressDialog
public to your Activity
progressDialog = ProgressDialog.show(ProjectListActivity.this,
"Please wait...", "Loading...");
new Thread() {
public void run() {
try {
String project = titles.get(position - 1);
performBackgroundProcess(project);
ProjectListActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
progressDialog.dismiss();
}
});
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
}
}.start();
but it is not a good approch use AsyncTask.
Solution 2:
private class ProgressTask extends AsyncTask<String, Void, Boolean> {
private ProgressDialog dialog = new ProgressDialog(HomeActivity.this);
protected void onPreExecute() {
this.dialog.setMessage("Please wait");
this.dialog.show();
}
protected Boolean doInBackground(final String... args) {
try {
Utilities.arrayRSS = objRSSFeed
.FetchRSSFeeds(Constants.Feed_URL);
return true;
} catch (Exception e) {
Log.e("tag", "error", e);
return false;
}
}
@Override
protected void onPostExecute(final Boolean success) {
if (dialog.isShowing()) {
dialog.dismiss();
}
if (success) {
// display UI
txtTitle.setText(Utilities.RSSTitle);
}
}
Solution 3:
This is how I implemented it. Copying the code here for others. Hopefully it works for you as well. You can copy this function "display_splash_screen()" and call it from your OnCreate() function (or whereever it is needed).
My Dialog (Splash Screen) R.layout.welcome_splash_screen is displayed, and then in a thread I dismiss the dialog after 3 secs.
`
private void display_splash_screen() {
try{
// custom dialog
final Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.welcome_splash_screen);
dialog.setTitle("Bulk SMS");
dialog.setCancelable(true);
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
Thread thrDialogClose = new Thread(){
@Override
public void run() {
super.run();
try {
// Let the dialog be displayed for 3 secs
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
dialog.dismiss();
}
};
thrDialogClose.start();
}});
dialog.setCanceledOnTouchOutside(true);
dialog.show();
}catch (Exception ex){
Log.e("Bulk SMS:", ex.getStackTrace().toString());
}
}
`
Post a Comment for "Application Showing Black Screen?"