2

How can I install a rotating progress bar (or dialog) during long transition between activity's? I've seen solutions with help realize AsyncTask - I did as mentioned in a post the link will How to display progress dialog before starting an activity in Android? , but the problem is that the progress bar is not spinning.

package expir.java.file;

import java.io.IOException;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;

public class ExpirActivity extends Activity {    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);        
        Button mapButton = (Button)findViewById(R.id.first_button);
        mapActivityIntent = new Intent(this, MyMapActivity.class);
        pDialog = new ProgressDialog(this);

        mapButton.setOnClickListener(new View.OnClickListener() {           
            public void onClick(View v) {
                pDialog.setMessage("Loading...");
                new MyTask(pDialog).execute();              
            }   
        });

        Button downloadButton = (Button)findViewById(R.id.second_button);        
        downloadButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {               
                as.DownloadFromUrl("0", "null");;
            }
        }); 
        Button parseButton = (Button)findViewById(R.id.third_button);        
        parseButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {               
                SAXParserCreateDataBase gi = new SAXParserCreateDataBase();
                try {
                    gi.start(ExpirActivity.this);
                } catch (SAXException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (ParserConfigurationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        });
        Button updateButton = (Button)findViewById(R.id.fourth_button);        
        updateButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {               
                SAXParserCreateDataBase gi = new SAXParserCreateDataBase();
                try {
                    gi.update(ExpirActivity.this);
                } catch (ParserConfigurationException e) {
                    e.printStackTrace();
                } catch (SAXException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }); 
    }    

    public class MyTask extends AsyncTask<Void, Void, Void> {
          public MyTask(ProgressDialog progress) {
            this.progress = progress;
          }

          public void onPreExecute() {
            progress.show();
          }

          public Void doInBackground(Void... unused) {
            startActivity(mapActivityIntent);
            return null;            
          }

          public void onPostExecute(Void unused) {
            progress.dismiss();
          }
          ProgressDialog progress;
    }


    DownloadPrimaryDate as = new DownloadPrimaryDate();
    Intent mapActivityIntent;
    ProgressDialog pDialog;
}

UPDATE:

LogCat results:

FirstActivity.onCreate()

FirstActivity.onStart()

FirstActivity.onResume()

FirstActivity.onPause()

SecondActivity.onCreate()

SecondActivity.onStart()

SecondActivity.onResume()

FirstActivity.onStop()

This explains why there is so.

UPDATE
In my realize what I was thinking - not all of my attempts to implement this transition between the activity were even.

Community
  • 1
  • 1
Siruk Viktor
  • 504
  • 1
  • 8
  • 30
  • if u are actually between the two activities ... on which VIEWGROUP do you think your progress bar will appear??? The progreeBar is hanged because the UI is blocked! I dont think you can show ProgressBar between two activities... (after onDestroy of 1st and before onCreate of second) – Aditya Nikhade Sep 06 '12 at 12:17
  • @Aditya Nikhade Your statement makes sense, but - as I understand it AsincTask allows separate display of dialogue from the activity itself (maybe I'm wrong.) I do not understand how you can implement in printsygt conceived by me - I've tried to allocate for this purpose a separate thread and execute code that should fire when you press the button - but it gave cover those results. – Siruk Viktor Sep 06 '12 at 12:28
  • Lets talk simple... what u actually want to show and when? make it clear between the activities? or before the 1st ends? or before 2nd starts? – Aditya Nikhade Sep 06 '12 at 12:30
  • @Aditya Nikhade The situation is this - after clicking on the button to load the card activity. In fact, when you click on the first activity as it stops but remains visible after 3-4 seconds displays a map - this time can be explained by the fact that before you show the map, the application knows the coordinates and analyzes database SQLite (about 3000 lines). I wish that the 3-4 seconds the screen displayed progressbar (or ProgressDialog). – Siruk Viktor 5 mins ago – Siruk Viktor Sep 06 '12 at 12:51
  • So put an AsyncTask at the time of the click... put dialog.show in the onPre dialog.dismiss in onPost and the think that was been done on the click of button inside the doInBackground..... So when the tracking of position starts the dialog appears and when it completes dialog goes!! – Aditya Nikhade Sep 06 '12 at 13:07
  • @Aditya Nikhade And what is the solution? – Siruk Viktor Sep 06 '12 at 13:16
  • i saw your code now again... u are calling another activity in doInBackground.... so the VIEW of the activity u are calling is getting finished... so the dialog which is started gets leaked... so i dont think you can show the dialog there... – Aditya Nikhade Sep 06 '12 at 13:19
  • You should show progress dialog in AsyncTask of that activity which you want to start next...not in current activity... – Priyank Patel Sep 10 '12 at 06:41
  • @Priyank Patel How this is possible - if the transition to the second activity I still check the first activity (stopped) because the system takes time (about 2-3 seconds) to conduct all activities in onCreate () ..... onResume () methods. I tried to make the suggested option - but did not work, because the first activity remains check until all the actions for the map display are not met - and because ProgressDialog not displayed - it overlaps the first Halted activity. – Siruk Viktor Sep 10 '12 at 09:07
  • How about: create dummy, empty activity without putting it on activities stack > in dummy - display dialog > start your time-consuming activity (passing handler to dialog) > after your activity is successfully loaded and created remove dialog via handler. Just an idea :) – alex Sep 10 '12 at 13:04
  • @alex The idea is good, but - this implementation will not work, the reason for everything - especially the work of the activity life cycle - if I start to load the "heavy" activity is the activity with the dialog immediately will pause and will remain visible until fully loaded "heavy" activity. – Siruk Viktor Sep 12 '12 at 07:44

1 Answers1

0

I see two solutions to this depending on where the task is that takes so long time.

If the long task is performed by the first activity create a progress dialog when the button is pressed, set the onShowListener to his dialog, in the onShow callback start your async task. When the task is finished dismiss your progress dialog and start the next activity.

If the long task is performed by the next activity just set a simple layout in the activities onCreate and creata a progress dialog, set the onShowListener and in onShow start your AsyncTtask and when it's finished load the rest of the ui and dismiss the dialog.

sanna
  • 1,165
  • 1
  • 16
  • 26