Created
May 6, 2018 06:58
-
-
Save kevalpatel2106/b683043f9325f6feb4a611dfb09cafec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.kevalpatel2106; | |
import android.os.AsyncTask; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.v7.app.AppCompatActivity; | |
import android.widget.TextView; | |
/** | |
* Created by Keval on 06/05/18. | |
* | |
* @author <a href="https://github.com/kevalpatel2106">kevalpatel2106</a> | |
*/ | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(@Nullable final Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
new Thread(new Runnable() { | |
@Override | |
public void run() { | |
//Here I am executing the task from diffrent Java thread. | |
//So, It doesn't have looper. | |
new CustomAsync().execute(); | |
} | |
}).start(); | |
} | |
//Custom async task that does nothing. | |
class CustomAsync extends AsyncTask<Void, Void, Void> { | |
@Override | |
protected Void doInBackground(final Void... voids) { | |
try { | |
Thread.sleep(5000L); | |
} catch (InterruptedException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
@Override | |
protected void onPostExecute(final Void aVoid) { | |
super.onPostExecute(aVoid); | |
//Lets update the status text to "Done". | |
//Task is finished. | |
((TextView)findViewById(R.id.status_tv)).setText("Done"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment