androidandroid-asynctaskandroid-webservice

Reset Android Activity


I have an activity in android application and from that I am calling a method of an AsyncTask class which is calling a webservice. I want to reset/reload my activity on the basis of the result i get from that method. How can I reset my activity from that class?


Solution

  • You can try the following

    Pass calling Activity context to your AsyncTask in constructor and save it in a variable Context context.

    Then in your PostExecute method of AsyncTask, write following lines :

            Intent targetIntent = new Intent(context, TargetActivity.class);
                // Add your data to intent
            targetIntent.putExtra("intent_extra_key", "intent_extra_value");
            context.startActivity(targetIntent);
            ((Activity) context).finish();
    

    Revert back for any issue.