Make a transition between activitys

2019-07-15 16:37发布

I need to make a transition screen, ou just put a dialog, because the app give a black screen when is creating the database.

I have google, and find some solutions for this. One of then, is just put a progress dialog when the database is been created.

My problem, and newbie question is, where do i put the progress dialog.

A -> BlackScreen -> B where A is the inicial menu, and B the other screen. I have tried to put the dialog on A and/or in B and dont work. So where can i put the code of the progress dialog, so it shows in the BlackScreen ?

2条回答
来,给爷笑一个
2楼-- · 2019-07-15 16:52
For that You have to use Async task : 

class DownloadAsyncTask extends AsyncTask<String, String, Void>
    {

        ProgressDialog progressDialog;


        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            progressDialog = ProgressDialog.show(Login.this, "", "Please Wait ...");
        }



        @Override
        protected Void doInBackground(String... arg0) {

            //Do your Task
        }

        @Override
        protected void onProgressUpdate(String...values){
            super.onProgressUpdate(values);




        }

        @Override
        protected void onPostExecute(Void result){
            super.onPostExecute(result);
            progressDialog.dismiss();
        }

    }

//Create the Object

DownloadAsyncTask downloadAsyncTask = new DownloadAsyncTask(); downloadAsyncTask.execute();

now till your work get's completed it shows progress dialog inside the doInbackground write your logic and onPostExecute dismiss the dialog and call Intent of other Activity.

查看更多
走好不送
3楼-- · 2019-07-15 17:10

Make use of Asyntask . put your database operation of creating database in asyntask in pre execute start dialog post execute cancel dialog in background perform database operation

http://developer.android.com/reference/android/os/AsyncTask.html

查看更多
登录 后发表回答