android - How can I run an AsyncTask with a dialog after finishing activity? -


I have two activities, here is a standard use case for displaying one entry and creating another. :

  • The user opens the app and displays the entries.
  • The user clicks the button to create a new button and it opens the new activity.
  • The user ends up creating the entry and clicking "Done".
  • Ends with the activity set () and ends ().

    What I want to add runs after an AsyncTask view activity is completely loaded. It displays a dialog when AsyncTask is running. The problem is, when I put this code in onActivityResult ():

      @OverrideActivative results on the public vacuum (int requestcode, INC results, resulting data) {super.onActivityResult (requestCode, ResultCode, info); Switch (result code) {case (activity. RSULDOK): {Mentry listfragment.update content (); RunAsyncTaskHere (); }}}   

    Before AsyncTask runs before it goes back to main activity, and no dialogue is displayed. Any ideas what I can do?

    EDIT: AsyncTask is here.

      Public Static Class login entities AsyncTask & lt; String, zero, integer & gt; {Protected string user name = ""; Protected string password = ""; Protected Progress Dialog dialog; Protected Boolean Show Deals; Public Login Task (Boolean SD) {this.showDialogs = sd; } @ Override Protected Zero on PreExecute () (if (this.showDialogs) Dialogues = Progress DIOL. Show (MainActivity.getContext (), Blank, "Login in ...")}} @ Override Protected Integer Doign Background (string. .. login) {if (Config.DEBUG) log.d. (Config.APP_NAME, "InInBackground (LogInTask"); HttpResponse response = null; string user name = login [0]; string password = login [1]; Try {HttpPost httpPost = new HttpPost (URL_BASE + URL_LOGIN); // main JSON login method JSONObject json = new JSONObject (). Put ("user", new Input ("remember_me", Config.REMEMBER_LOGIN)); This.username = Username; This.password = password; String From = new string identity (json.toString ()); HttpPost.setHeader ("Accept", "App / JS"); HttpPost.setHeader ("Content-Type", "App / JS"); httpPost.setEntity Se); response = httpclient.execute (httpPost); string response entity = EntityUtils.toString (response.getEntity ()); JSONObject Results = New JSONObject (responseEntity); Return result. Boolean ("success")? 1: KEY_ERROR; // if 1 is successful and 1 if not, then} 1 (come back to capture) (in print staxress); KEY_ERROR; } Hold (exception e) {e.printStackTrace (); Return KEY_ERROR; }} @Override Secure Zero at postexec (integer result) {if (this.showDialogs) {dialog.dismiss (); String text = result == 1? "Login succeeded." : "Login failed!"; MakeToast (text); }}}   

    Edit 2: I tried to do this:

      Boolean is needed TOUpdate = false; Override public zero at @activityResult (integer requestcode, integer result code, intent data) {super.onActivityResult (requestCode, resultcode, data); Switch (result code) {case (activity. RSULDOK): {Mentry ListFragment.Update Content (); NeedToUpdate = true; }}} @ Override Public Records on Resum () {Super. Rebirth (); If (needToUpdate) {runAsyncTaskHere (); MEntryListFragment.updateContent (); } NeedToUpdate = false; }   

    And it does the same thing.

    EDIT 3: Here are the related sections of Android management:

      & lt; Activity Android: Name = ". Main Activity" Android: label = "@ string / app_name" Android: Screen Orientation = "Portrait" & gt; & Lt; Intent-Filter & gt; & Lt; Action Android: name = "android.intent.action.MAIN" /> & Lt; Category android: name = "android.intent.category.LAUNCHER" /> & Lt; / Intent-Filter & gt; & Lt; / Activity & gt; & Lt; Activity Android: Name = "AddEntryActivity" Android: label = "@ string / app_name" Android: Screen Orientation = "Portrait" Android: configChanges = "orientation" />    

    1. when you click the button to create a new entry Launch new activity. But do not end the activity after the intentions ()
    2. After creation, and clicking, just close the current activity. (Call the call) () Call
    3. Write mEntryListFragment.updateContent this method in the beginning () of the activity that displays the entries.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -