1. Download our Official Android App: Forums for Android!

Apps How to build a loading please wait from a activity that not async

Discussion in 'Android Development' started by HeavensSentSword, Apr 13, 2016.

  1. HeavensSentSword

    HeavensSentSword Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    So this is a tuff one. I have a activity that calls a class that call a http downloader which is the async task. What I want to do is have a please wait loading screen notification for the user while the activity is getting all the data from the web. I don't have a clue on how to get the loading screen to be called. Usually you would have it in the async task but my async task does not have a view. How to best go about doing this?
    Thank you for any help.
    My http client does have a doInBackground() so should I put the on preExecute and postExecute there? But then how would my main method which is twice removed know when its down and when its not.

     

    Advertisement

  2. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
  3. HeavensSentSword

    HeavensSentSword Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Ok so I have been working on this and still nothing. What is happening is that when a button is clicked it starts the activity and starts to process all the methods, but it linger on the first activity until everything is done loading. I don't want that I want the progress dialog. It just won't show. Any thoughts on this?

    Code (Java):
    1.  Tracker customerPageTracker;
    2.  
    3.     ProgressDialog progress;
    4.  
    5.     String myName;
    6.     int myTotal;
    7.     int myAvaliable;
    8.     String myRank;
    9.     String customerNumber;
    10.     Bitmap barcode = null;
    11.  
    12.     String customrURl;
    13.  
    14.     ImageView imageview;
    15.     TextView num ,pointText, pointsEarned,rank,customerName,myPurchases;
    16.     Button logout, account, more;
    17.  
    18.     //Variables to send to the server for customers
    19.     String customer_id;
    20.     String android_id;
    21.     String notification_id;
    22.     String operating_system_type;
    23.  
    24.     Tracker mTracker;
    25.     AnalyticsApplication app;
    26.     Activity myActivity;
    27.     Context customerPageContext;
    28.  
    29.     CustomerInfoJsonParser cijp;
    30.  
    31.  
    32.     @Override
    33.     protected void onCreate(Bundle savedInstanceState) {
    34.         super.onCreate(savedInstanceState);
    35.         setContentView(R.layout.mypage_layout);
    36.         //build statusbar
    37.         CustomStatusbar customStatusbar = new CustomStatusbar();
    38.         customStatusbar.makeSatusBar(this);
    39.         progress = ProgressDialog.show(this, "Loading", "PleaseWait", true);
    40.         cijp  = new CustomerInfoJsonParser();
    41.  
    42.         customrURl = getString(R.string.customerCRM);
    43.  
    44.         customerPageContext = this;
    45.         //generate the UI
    46.         getUIAssignments();
    47.  
    48.         // [START shared_tracker]
    49.         // Obtain the shared Tracker instance.
    50.         app = (AnalyticsApplication) getApplication();
    51.         mTracker = app.getDefaultTracker();
    52.         // [END shared_tracker]
    53.         mTracker.setScreenName("CustomerPage Screen");
    54.         mTracker.send(new HitBuilders.ScreenViewBuilder().build());
    55.  
    56.         customerPageTracker = ((AnalyticsApplication) getApplication()).getDefaultTracker();
    57.         myActivity = this;
    58.  
    59.         asignValues(cijp, myPurchases);
    60.  
    61.         new Thread(new Runnable() {
    62.             @Override
    63.             public void run()
    64.             {
    65.                 // do the thing that takes a long time
    66.                 //fill in the customers information
    67.                 buildBarcode(imageview, num);
    68.  
    69.                 runOnUiThread(new Runnable() {
    70.                     @Override
    71.                     public void run()
    72.                     {
    73.                         createUI(pointText, pointsEarned, rank, customerName);
    74.                         getSendingData();
    75.  
    76.                         progress.dismiss();
    77.                     }
    78.                 });
    79.             }
    80.         }).start();
    81.  
    82.  
    83.  
    84.         //Build the rules for the buttons
    85.         myButtons(customerPageTracker);
    86.         ButtonControler bc = new ButtonControler();
    87.         bc.buttonPressed(this);
    88.  
    89.  
    90.     }
     
  4. HeavensSentSword

    HeavensSentSword Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Ok so I updated this significantly now I am using a local class that is a async. I feel that this is a step in the right direction, but still does not work.

    It now displays the dialog but never goes away. I feel that it has an issues with not knowing that it is done processing so it just keeps running. Now this is calling a json parser which is calling a http downloader. If that makes any difference.
    Here is what I am doing now
    Code (Java):
    1.  private class runningMan extends AsyncTask<Void, Void, Void>
    2.     {
    3.         @Override
    4.         protected void onPreExecute() {
    5.             super.onPreExecute();
    6.  
    7.             Log.d("Runningman: ", "Started running");
    8.             //this method will be running on UI thread
    9.             progress = ProgressDialog.show(customerPageContext, "Loading", "PleaseWait", true);
    10.             progress.show();
    11.         }
    12.  
    13.         @Override
    14.         protected Void doInBackground(Void... params) {
    15.  
    16.             Log.d("Runningman: " , "Is still running");
    17.             asignValues(cijp, myPurchases);
    18.             buildBarcode(imageview, num);
    19.  
    20.  
    21.             return null;
    22.         }
    23.         @Override
    24.         protected void onPostExecute(Void result) {
    25.             super.onPostExecute(result);
    26.  
    27.             Log.d("Runningman: " , "Finished runing");
    28.             //this method will be running on UI thread
    29.             createUI(pointText, pointsEarned, rank, customerName);
    30.             getSendingData();
    31.  
    32.             progress.dismiss();
    33.         }
    34.  
    35.  
    36.     }
    37.  
    38. }
    39.  
     
  5. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
    Is onPostExcecute() being called?
     
  6. HeavensSentSword

    HeavensSentSword Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Not that I have seen in my logs. It never seems to get down there unless I have nothing in the background method.
     
  7. LV426

    LV426 I say we take off and nuke this place from orbit
    Recognized Developer
    Rank:
     #12
    Points:
    1,988
    Posts:
    9,176
    Joined:
    Oct 16, 2015

    Oct 16, 2015
    9,176
    13,681
    1,988
    Male
    Software developer
    South West of England
  8. HeavensSentSword

    HeavensSentSword Well-Known Member
    Thread Starter
    Rank:
    None
    Points:
    93
    Posts:
    134
    Joined:
    Jan 19, 2016

    Jan 19, 2016
    134
    36
    93
    Male
    Yeah that may be the issue. I was thinking that my self seeing that if the onPost doesnt know when the doInBackground is done. It maybe a little deeper than that but I feel that this is the main issue with what is going on
     

Share This Page

Loading...