Skip to content

Instantly share code, notes, and snippets.

@markcerqueira
Last active August 29, 2015 14:19
Show Gist options
  • Save markcerqueira/aa118d6e9049f73f6a05 to your computer and use it in GitHub Desktop.
Save markcerqueira/aa118d6e9049f73f6a05 to your computer and use it in GitHub Desktop.
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