Method 1:
If the activity is still in the background, pass context to AsyncTask and create an instance of your settings activity.
SettingsActivity settingsActivity = (SettingsActivity) context;
then call the method in onPostExecute()
settingsActivity.setNewSetting();
And you have your setNewSetting() method in your SettingsActivity application. It should be publicly available and put some checks on null values.
Method 2:
Use an interface delegate. Create an interface:
public interface TaskListener { void onComplete(); }
Pass it to AsyncTask when it executes, for example:
new MyAsyncTask(params, params, new TaskListener() { @Override public void onComplete () {
You will get it in your AsyncTask constructor:
public MyAsyncTask (String params, String param2, TaskListener taskListenerDelegate) { this.taskListenerDelegate = taskListenerDelegate; }
Call it onComplete() in onPostExecute() :
taskListenerDelegate.onComplete();
Method 3
Not recommended, but you can also try using startActivityForResult() . And listen to onActivityResult() to apply the changes.
source share