I read in AsyncTask document , Threading rules section that execute(Params...) must be invoked on the UI thread. But when I check this demo , it works fine . Can anyone help me to figure out what I am missing here ?
public class MainActivity extends AppCompatActivity { public static final String TAG = "MainActivity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button) findViewById(R.id.btn); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new Thread(new Runnable() { @Override public void run() { new PublicTask().execute(); } }).start(); } }); } public class PublicTask extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute() { super.onPreExecute(); Log.i(TAG, "onPreExecute called"); } @Override protected Void doInBackground(Void... voids) { Log.i(TAG, "doInBackground called"); return null; } } } This is the Log I am getting. No crash. I wonder , why?
12-17 00:28:41.317 18152-18193/? I/MainActivity: onPreExecute called 12-17 00:28:41.340 18152-18194/? I/MainActivity: doInBackground called