java - How to connect to network in Android using AsyncTask -
I write a code like the one below to connect to the network in Android
public Squared MainActivity ActionBarActivity {@ Override Protected Zero (created from Bundle, Intrestance) {Super. Contents (Saved Instantstate); SetContentView (R.layout.activity_main); InitTask function = new InitTask (); Toast. Make text (getApplicationContext), task.doInBackground (), toast .LENGTH_LONG). Show (); } Private class InitTask AsyncTask and lt; Zero, zero, string & gt; {Secure string extends doInBackground (zero ... p) {// Network talk ... return string; }}} I used the AsyncTask but is NetworkOnMainThreadException
is it in main activity Is not permission to make asynchronous task as internal category?
Because you are calling the doInBackground method by making the InitTask class object
Other Thread Call to execute the method doInBackground method to start the AsyncTask and Use the onPostExecute method to show the toast message when doInBackground method execution is complete:
@Override Secure zero on PostExecute (string result) {Toast.makeText (getApplicationContext (), "Work Completed!", Toast. LNNHHLog) Show (); }
Comments
Post a Comment