The easiest way to do threading in Android is using an AsyncTask.
I'm not sure if you would like to pass each of these methods an argument, or if you would like anything back from them; but let's assume you're not passing or expecting anything.
public void onReceive(Context context, Intent intent) {
// start the first method
new AsyncTask<Integer, Integer, Integer>() {
@Override
protected Integer doInBackground(Integer... params) {
getA();
}
}.execute();
// start the second method
new AsyncTask<Integer, Integer, Integer>() {
@Override
protected Integer doInBackground(Integer... params) {
getB();
}
}.execute();
// start the third method
new AsyncTask<Integer, Integer, Integer>() {
@Override
protected Integer doInBackground(Integer... params) {
getC();
}
}.execute();
}
The <Integer, Integer, Integer>
params stand for the types of the parameters you would like to pass to the task, the type of progress updates, and the returned result type.
If you would like to pass each method some arguments, then change the first Integer
to the type of argument you would like to pass, then add these arguments in the execute()
method.
If you would like to start an activity and send it some data from the receiver, you should do it using an Intent.
public void getA(Context context, Object dataToPass) {
// replace DestinationActivity with the Activity that you want to start
Intent i = new Intent(context, DestinationActivity.class);
// add the data that you want to pass
i.putExtra("some-constant", dataToPass);
// start the actual activity
context.startActivity(i);
}
In that case, you would have to change the call to getA()
in the onReceive()
method to add the context and the data that you want to pass.
Reference: http://developer.android.com/reference/android/os/AsyncTask.html