Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Why!?
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
doWork("string_param");
}
// Note the parameter variable name (i.e. string)
private void doWork(final String string) {
AsyncTask<Void, Void, String> asyncTask = new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
return "string_async_task";
}
@Override
protected void onPostExecute(String resultString) {
// Why is this allowed? If I leave this as is, the log below
// prints "string_async_task". If I comment this line out, it
// prints "string_param"
String string = resultString;
Log.e("MainActivity", string);
}
};
asyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
}
// class file decoded using JD-GUI (http://jd.benow.ca/)
public class MainActivity extends ActionBarActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(2130968599);
doWork("string_param");
}
private void doWork(String string)
{
AsyncTask<Void, Void, String> asyncTask = new AsyncTask()
{
protected String doInBackground(Void... params)
{
return "string_async_task";
}
protected void onPostExecute(String resultString)
{
String string = resultString;
Log.e("MainActivity", string);
}
};
asyncTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, new Void[0]);
}
}
// class file decoded using JD-GUI (http://jd.benow.ca/)
class MainActivityActivity$1 extends AsyncTask<Void, Void, String>
{
MainActivityActivity$1(MainActivityActivity paramMainActivityActivity) {}
protected String doInBackground(Void... params)
{
return "string_returned_by_async_task";
}
protected void onPostExecute(String resultString)
{
String string = resultString;
Log.e("MainActivity", "paramString = " + string);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.