how can I call a method of a new intent?
My aim is to have an Activity which starts an AsyncTask. From my main Activity I want so start this as an Intent, and to
get the task in order to check if it is still running (if foo() gets executed again).
class MainActivity extends Activity () {
foo() {
Intent i = new Intent(this, MyTaskActivity.class);
startActivity(i);
//AsyncTask task = i.getTask(); ??
//if (task.getStatus() ==...)
}
}
class MyTaskActivity exteds Activity() {
private AsyncTask task;
public AsyncTask getTask() {
return this.task;
}
@Override
onCreate(..) {
task = new MyTask().execute();
}
private class MyTask extends AsyncTask<..>() {
}
}
//solution: call this from the main activity:
((MyTaskActivity) getAppContext()).getTask();
You can catch the end of your task and send a broadcast catched by your main activity or restart your main activity (if it’s defined with specific flag in your manifest the main activity should be displayed on top).
One thing is sure : you can’t control the child activity.