Skip to content Skip to sidebar Skip to footer

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() {

    publicvoidrun() {

        try {
            String project = titles.get(position - 1);

            performBackgroundProcess(project);
            ProjectListActivity.this.runOnUiThread(new Runnable() {

        @Override
        publicvoidrun() {
            progressDialog.dismiss();

        }
    });

        } catch (Exception e) {

            Log.e("tag", e.getMessage());

        }


    }

}.start();

but it is not a good approch use AsyncTask.

Solution 2:

privateclassProgressTaskextendsAsyncTask<String, Void, Boolean> {

    privateProgressDialog dialog = newProgressDialog(HomeActivity.this);

    protectedvoidonPreExecute() {
        this.dialog.setMessage("Please wait");
        this.dialog.show();
    }

    protectedBooleandoInBackground(final String... args) {
        try {

            Utilities.arrayRSS = objRSSFeed
                    .FetchRSSFeeds(Constants.Feed_URL);
            returntrue;
        } catch (Exception e) {
            Log.e("tag", "error", e);
            returnfalse;
        }
    }

    @OverrideprotectedvoidonPostExecute(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.

`

privatevoiddisplay_splash_screen() {
    try{
        // custom dialogfinalDialogdialog=newDialog(MainActivity.this);
        dialog.setContentView(R.layout.welcome_splash_screen);
        dialog.setTitle("Bulk SMS");
        dialog.setCancelable(true);

        dialog.setOnShowListener(newDialogInterface.OnShowListener() {
            @OverridepublicvoidonShow(DialogInterface dialogInterface) {
                ThreadthrDialogClose=newThread(){
                    @Overridepublicvoidrun() {
                        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?"