create new async task with sending callback to ui - android

i have listview and the content of listview change depend on user interface
and i need to know how to create new instance of async task if i implement callback receiver
public interface CallbackReciever {
public void receiveData(String result);
}
and the async task class
public abstract class ConnectDB extends AsyncTask<String, String, String> implements CallbackReciever {
ProgressDialog pDialog;
Context context;
public String resString;
public ConnectDB(Context context)
{
// TODO Auto-generated constructor stub
this.context=context;
}
#Override
public abstract void receiveData(String object);
/**
* Before starting background thread Show Progress Dialog
* */
#Override
protected void onPreExecute()
{
super.onPreExecute();
pDialog = new ProgressDialog(context);
pDialog.setMessage("Loading. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args)
{
// getting JSON string from URL
resString =Connection.Get(path);
return resString;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url)
{
// dismiss the dialog after getting all products
pDialog.dismiss();
if(resString!=null)
{
receiveData(resString);
}
}
}
and the MainActivity class
public class MainActivity extends Activity {
ListView list;
MovieAdapter adapter;
public ArrayList<Movie> data=new ArrayList<Movie>();
public ConnectDB conDB;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final Context t=this.getApplicationContext();
setContentView(R.layout.activity_main);
conDB= new ConnectDB(MainActivity.this) {
#Override
public void receiveData(String result) {
// TODO Auto-generated method stub
try {
Log.d("ds", result);
JSONObject json = null;
JSONArray jArray = new JSONArray(result);
int i=0;
while ( i< jArray.length())
{
final Movie tmp=new Movie();
json = jArray.getJSONObject(i);
tmp.setName(json.getString("name"));
tmp.setUrl(json.getString("image"));
tmp.setDescription(json.getString("desc"));
tmp.setTime(json.getString("time"));
tmp.setTime(Utils.ChangeTolocaclTime(tmp.getTime()));
tmp.setWatch(Utils.CanWatch(tmp.getTime()));
data.add(tmp);
i++;
}
}
catch (JSONException e) {
e.printStackTrace();
}
list=(ListView)findViewById(R.id.list);
if(data.size()==0)
{
Toast.makeText(t, "Server Error", Toast.LENGTH_SHORT).show();
list.setVisibility(View.INVISIBLE);
}
// Create custom adapter for listview
adapter=new MovieAdapter(MainActivity.this, data,t);
//Set adapter to listview
list.setAdapter(adapter);
}
};
conDB.execute("MBC2");
}

The activity should implement the receiver and the async task should call it, something like this:
public class MyActivity extends Activity implements CallbackReceiver{
#Override
public void onCreate(Bundle savedInstanceState) {
//Set everything up
MyAsyncTask task = new MyAsyncTask();
task.setOnDataReceivedListener(this);
task.execute();
}
#Override
public void onReceiveData(String data){
//Do something with the data
}
}
Then, in the async task, you can call the receiver method in onPostExecute
public abstract class MyAsyncTask extends AsyncTask<String, String, String>{
private CallbackReciever receiver = null;
public void setOnDataReceivedListener(CallbackReciever receiver){
this.receiver = receiver
}
protected void onPostExecute(String file_url)
{
if(receiver != null){
receiver.onReceiveData(file_url);
}
}
}
The second way to do this is to simply make an anonymous inner class of your async task and override onPostExecute:
public class MyActivity extends Activity implements CallbackReceiver{
#Override
public void onCreate(Bundle savedInstanceState) {
//Set everything up
MyAsyncTask task = new MyAsyncTask(){
#Override
protected void onPostExecute(String file_url){
//Do what you want with your data here
}
};
task.execute();
}
}

Related

Progress Dialog in OnPreExexcute() not working

I am newbie to android and facing issue on Progress dialog,though myriad question and answers are here but none is working for me.Any help will be greatly appreciated.
I want to show a spinning wheel on my login page of app,all my Async Task activties are in different class and I am passing the activity reference to my HttpClientHelper class which is handling Async Task.No progress dialog appears when i click on Login button.
Most of the answers have mentioned to implement the Async Task in Activity class but i have created a utility class which is handling the POST/GET in background.
Hence in thin non activity class i dont have the reference of Context so i passed LoginActivity.this in HttpClientHelper constructor.
AM i doing something wrong here.Due to multiple use of POST/Get i can implement them in each activity.
Please find the sample files these are not actual code I am posting the steps
public class LoginActivity extends AppCompatActivity {
btnSignIn.setOnClickListener(new View.OnClickListener() {
HttpClientHelper httpClientHelper = new HttpClientHelper(LoginActivity.this);
JSONObject json = httpClientHelper.postJSON(apiURL
, params);
...... rest of the code
}
}
Here is the HttpClientHelper
public class HttpClientHelper {
private Activity activity;
private static HttpURLConnection urlConnection;
private static String result;
private static JSONObject jsonObject = null;
public HttpClientHelper(){
}
public HttpClientHelper(Activity activity){
this.activity=activity;
}
public JSONObject postJSON(String url, Map<String, String> params) {
Params param = new Params(url, params);
PostAsyncTask myTask = new PostAsyncTask();
try {
jsonObject = myTask.execute(param).get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
return jsonObject;
}
private class PostAsyncTask extends AsyncTask<Params, String, JSONObject> {
JSONObject json = null;
ProgressDialog progressDialog;
public PostAsyncTask(){
}
#Override
protected void onPreExecute(){
super.onPreExecute();
progressDialog = new ProgressDialog(activity);
progressDialog.setTitle("Login");
progressDialog.setMessage("Loading..Please Wait");
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(true);
progressDialog.show();
}
#Override
protected JSONObject doInBackground(Params... args) {
json = HttpClientHelper.getJSONFromURL(args[0].url, args[0].params);
return json;
}
#Override
protected void onPostExecute(JSONObject json) {
super.onPostExecute(json);
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
}
}
Progress dialogue is associated with UI and any updates in view is not recommended to put inside a AsyncTask. UI updates or changes should occur in the UI thread.
In your case, the desired result can be achieved by setting a listener to the AsyncTask. Simply add a listener class and implement the listener in the activity class.
Here's an example.
HttpResponseListener.java
public interface HttpResponseListener {
public void httpResponseReceiver(String result);
}
Now in your LoginActivity implement the interface like this:
public class LoginActivity extends AppCompatActivity implements HttpResponseListener {
// rest of your code
// initialize your progress dialogue here and execute the asynctask
progressDialogue.show();
myTask.execute();
myTask.mHttpResponseListener = this;
#Override
public void httpResponseReceiver(String result) {
if(result == null)progressDialogue.dismiss();
else {
// Use result to serve your purpose
progressDialogue.dismiss();
}
}
}
Now in your AsyncTask class, set the result in post execute.
private class PostAsyncTask extends AsyncTask<Params, String, JSONObject> {
JSONObject json = null;
ProgressDialog progressDialog;
public HttpResponseListener mHttpResponseListener;
public PostAsyncTask(){
}
#Override
protected void onPreExecute(){
super.onPreExecute();
}
#Override
protected JSONObject doInBackground(Params... args) {
json = HttpClientHelper.getJSONFromURL(args[0].url, args[0].params);
return json;
}
#Override
protected void onPostExecute(JSONObject json) {
super.onPostExecute(json);
mHttpResponseListener.httpResponseReceiver("OK");
}
#Override
protected void onCancelled() {
mHttpResponseListener.httpResponseReceiver(null);
}
}

Android display a ProgressDialog on a ListActivity when using multiple external AsynTasks

So I am completely new to Andorid programming and can't seem to get a ProgressDialog to show on a ListActivity (ScheduleActiviy in my example) when running an AsyncTask from a separate class (GetGames in my example). I am attempting to use separate class for code re-usability. When I previously had the AsyncTask as an embedded class it seemed to work. I have posted what I believe to be all the relevant code. Any help would be great. Thanks!
ScheduleActivity.java
public class ScheduleActivity extends ListActivity
{
private final String PDIALOG_MSG = "Loading schedule...";
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.schedule);
ArrayList<HashMap<String, String>> gamesList = null;
try
{
// Loading information in Background Threads
gamesList = new GetGames(ScheduleActivity.this, PDIALOG_MSG).execute().get();
GetGames.java
public class GetGames extends AsyncTask<Void, Void, ArrayList<HashMap<String, String>>>
{
private Context context;
private ProgressDialog pDialog;
private String pDialogMsg;
public GetGames(Context ctx, String dialogMsg)
{
context = ctx;
pDialogMsg = dialogMsg;
}
#Override
public void onPreExecute()
{
super.onPreExecute();
pDialog = new ProgressDialog(context);
pDialog.setMessage(pDialogMsg);
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
#Override
public void onPostExecute(ArrayList<HashMap<String, String>> rtnList)
{
pDialog.dismiss();
}
Your ProgressDialog should probably be controlled on the Activity level instead of the AsyncTask level. Theoretically I don't see why how you're doing it wouldn't work, but I can show you a method which definitely works (it's what I do) and it organizes things a bit differently:
//In AsyncTask
#Override
protected void onPreExecute() {
showProgressDialog(R.string.importing_pages);
}
#Override
public void onPostExecute(Boolean b) {
hideProgressDialog();
}
//In Activity
public void showProgressDialog(int msgResId) {
showProgressDialog(getString(msgResId));
}
public void showProgressDialog(String msg) {
mProgressDialog = ProgressDialogHelper.buildDialog(this, msg);
mProgressDialog.show();
}
public void hideProgressDialog() {
if(mProgressDialog != null)
mProgressDialog.dismiss();
}
//My progress dialog helper class:
public class ProgressDialogHelper {
/**
* Creates a generic progress dialog with the specified message
*
* #param activity the activity which hosts the dialog. This must be an activity, not a context.
* #param msgResId the resId for the message to display
* #return a progress dialog
*/
public static ProgressDialog buildDialog(Activity activity, int msgResId) {
return buildDialog(activity, activity.getApplicationContext().getString(msgResId));
}
/**
* Creates a generic progress dialog with the specified message
*
* #param activity the activity which hosts the dialog. This must be an activity, not a context.
* #param msg the message to display
* #return a progress dialog
*/
public static ProgressDialog buildDialog(Activity activity, String msg) {
ProgressDialog dialog;
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
dialog = new ProgressDialog(new ContextThemeWrapper(activity, android.R.style.Theme_Holo_Dialog));
else
dialog = new ProgressDialog(activity);
dialog.setMessage(msg);
dialog.setCancelable(false);
return dialog;
}
}
You don't have to make a helper class if you don't want to, it's just how I organized it. The main idea here is that the progress dialog should be owned by the Activity instead of the AsyncTask.
Also, the context used must be the activity's, not getApplicationContext(). It looks like you have that part right though.
You can display Progress Dialogs using AsyncTasks. That's not a problem. I do it all the time. What may be the problem is the doInBackground() method. What do you have there?
I also generally nest the AsyncTasks within the Activity class, so that it can call other Activity class methods in the onPostExecute() method. Otherwise, in order for it to communicate back with your Activity you'll have to use something like a handler or static references.
public class TestActivity extends Activity {
private AsyncTask<Void, Void, ArrayList<String>> bgLoader;
private ArrayList<String> listOfStuff;
private TextView textView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
listOfStuff = new ArrayList<String>();
textView = (TextView) findViewById(R.id.textView);
textView.setText("Your list has " + listOfStuff.size() + " items in it!");
bgLoader = new MyAsyncTask(this, "Waiting...").execute();
}
private void resumeDoingStuff() {
try {
listOfStuff = bgLoader.get();
textView.setText("Your list has " + listOfStuff.size() + " items in it!");
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
public class MyAsyncTask extends AsyncTask<Void, Void, ArrayList<String>> {
private ProgressDialog progressDialog;
private String message;
private Context ctx;
public MyAsyncTask(Context context, String message) {
this.ctx = context;
this.message = message;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(ctx);
progressDialog.setMessage(message);
progressDialog.setIndeterminate(false);
progressDialog.setCancelable(false);
progressDialog.show();
}
#Override
protected ArrayList<String> doInBackground(Void... params) {
ArrayList<String> retList = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
try {
retList.add("TEST STRING " + i);
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return retList;
}
#Override
protected void onPostExecute(ArrayList<String> result) {
progressDialog.dismiss();
resumeDoingStuff();
}
}
}

Progess Dialog with fragment inside activity call asynctask

I have a main activity, which has a fragment inside, that calls an Asynctask.
Main Activity - The main activity has a ViewPager that loads the fragment.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.viewPager = (ViewPager)findViewById(R.id.pager);
this.mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(mAdapter);
/**
* on swiping the viewpager make respective tab selected
* */
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageSelected(int position) {
// on changing the page
// make respected tab selected
//actionBar.setSelectedNavigationItem(position);
//Toast.makeText(getApplicationContext(), "this is my Toast message!!! =)",
//Toast.LENGTH_LONG).show();
}
#Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
#Override
public void onPageScrollStateChanged(int arg0) {
}
});
Fragment - Makes Call to service
public class SomeFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.article_view, container, false);
ServiceHelper srv = new ServiceHelper(getActivity(), "GetHomeImage", postParameters, 2);
AsyncTask<String, Void, String> request = srv.execute();
return view;
}
}
Async Task Class - Show Progressdialog and make requests
public class ServiceHelper extends AsyncTask<String, Void, String> {
public ServiceHelper(Context c, String method, HashMap<String, Object> parameters, int requestType){
context = c;
this.method = method;
this.parameters = parameters;
this.requestType = requestType;
}
protected void onPreExecute(){
progressDialog = ProgressDialog.show(context, "Requisição", "Chamando Serviço", true, false);
}
protected String doInBackground(String... params) {
do stuff...
}
protected void onPostExecute(String result) {
progressDialog.dismiss();
}
}
The problem I'm facing is that the fragment is called, the request is made, but the Progessdialog only appears when the fragment is shown.
It's possible to show the Progressdialog when the call is made?
Thanks.
I think the simple way here is show progress dialog before call to execute AsyncTask. for closing progress dialog you should add a Listener to ServiceHelper and listen it to dismiss dialog on cancel or completion of task. here is code:
final Dialog progressDialog = ProgressDialog.show(context, "Requisição", "Chamando Serviço", true, false);
ServiceHelper srv = new ServiceHelper(getActivity(), "GetHomeImage", postParameters, 2);
srv.setListener(new ServiceHelperListener() {
public void onCancel() {
progressDialog.dismiss();
}
public void onCompelte() {
progressDialog.dismiss();
}
});
AsyncTask<String, Void, String> request = srv.execute();
and ServiceHelper class and Listener:
public class ServiceHelper extends AsyncTask<String, Void, String> {
private ServiceHelperListener mListener;
public ServiceHelper(Context c, String method, HashMap<String, Object> parameters, int requestType){
context = c;
this.method = method;
this.parameters = parameters;
this.requestType = requestType;
}
public void setListener(ServiceHelperListener listener) {
this.mListener = listener;
}
protected void onPreExecute(){
}
protected String doInBackground(String... params) {
do stuff...
}
protected void onPostExecute(String result) {
if (mListener != null) {
mListener.onCompelte();
}
}
#Override
protected void onCancelled(String s) {
super.onCancelled(s);
if (mListener != null) {
mListener.onCancel();
}
}
}
public interface ServiceHelperListener {
public void onCancel();
public void onCompelte();
}

Returning an ArrayList in android AsyncTask class

I have an android fragment which contains an android AsyncTask class implemented as follows
protected class getGraph extends
AsyncTask<GraphFragment, Void, GraphFragment> {
#Override
protected GraphFragment doInBackground(GraphFragment... params) {
performance = getPerformance(sharename);
return null;
}
protected void onPostExecute(GraphFragment Param) {
}
}
Now i want to return the value performance which is an ArrayList to the calling method.How do i achieve that?
Try this:
(replace "String" with whatever native variable type your data is)
protected class getGraph extends
AsyncTask<GraphFragment, Void, List<String>> {
List<String> performance = new ArrayList<String>();
#Override
protected GraphFragment doInBackground(GraphFragment... params) {
performance = getPerformance(sharename);
return null;
}
protected void onPostExecute(List<String> Param) {
}
}
Use following code.
public class calc_stanica extends AsyncTask<ArrayList<String>, Void, ArrayList<String>> {
ProgressDialog dialog;
#Override
protected void onPreExecute() {
dialog = new ProgressDialog(baraj_mapa.this);
dialog.setTitle("Calculating...");
dialog.setMessage("Please wait...");
dialog.setIndeterminate(true);
dialog.show();
}
protected ArrayList<String> doInBackground(ArrayList<String>... passing) {
ArrayList<String> result = new ArrayList<String>();
ArrayList<String> passed = passing[0]; //get passed arraylist
// Assign data to your Arralist from your method
result = getData();
//Some calculations...do your stuff here.
return result; //return result arraylist
}
protected void onPostExecute(ArrayList<String> result) {
dialog.dismiss();
// Get your arraylist here.
}
Take this aproach
protected class getGraph extends
AsyncTask<GraphFragment, Void, ArrayList<YOUROBJECT> {
#Override
protected ArrayList<YOUROBJECT> doInBackground(GraphFragment... params) {
performance = getPerformance(sharename);
return performance;
}
public void onPostExecute( ArrayList<YOUROBJECT> Param) {
}
}
In your other Class/MainActivity call it this way:
private void getSomething(){
new getGraph({
#Override
void onPostExecute(ArrayList<YOUROBJECT> Param){
//DO SOMETHING IN MAINACTIVITY
}
}).execute();
}
Do this way..
protected class getGraph extends
AsyncTask<GraphFragment, Void, ArrayList<String> {
#Override
protected GraphFragment doInBackground(GraphFragment... params) {
performance = getPerformance(sharename);
ArrayList<String> DATA=new ArrayList<String>();
/*
do the process and assign result in DATA
*/
return DATA;
}
protected void onPostExecute( ArrayList<String> Param) {
// Get your arraylist here.
}
}

How to set adapter of spinner by using Async Task Class

In my code I load a spinner adapter by using Async Task
In My case The ProgressDialog is Not dismissing
This is My code.
I want to show the item after adapter load and the progressDialog is to dismiss
Please Help me, Thanks
private class LoadMoreVehicals extends AsyncTask<Object, Integer, Object> {
#Override
protected void onPreExecute() {
progressBar = ProgressDialog.show(RegistrationScreen.this, "",
"Loading...");
progressBar.setIndeterminate(true);
progressBar.setIndeterminateDrawable(getResources().getDrawable(
R.anim.progressbar_handler));
super.onPreExecute();
}
#Override
protected Object doInBackground(Object... params) {
String countryUrl = ConstantURL.COUNTRY_URL;
getCounty(countryUrl);
countrySpinner
.setAdapter(new MyCustomSpinnerAdapter(
RegistrationScreen.this,
R.layout.spinner_dropdown,
countyList));
return null;
}
#Override
protected void onProgressUpdate(Integer... values) {
progressBar.getProgress();
}
#Override
protected void onPostExecute(Object result) {
progressBar.dismiss();
Log.e("Im in onPostExecute", "");
super.onPostExecute(result);
}
}
While programming in Android you should remember one thing that any task which draws something on the screen should be executed on the main thread. When you set the adapter then android calls the getView() method of the adapter and draws views on the screen. So you should set the adapter in the postExecute() method instead in doInBackground() method.
Here is a small sample to clear my point:
class MyTask extends AsyncTask<Void, Void, Void> {
ProgressDialog pd = new ProgressDialog(MainActivity.this);
#Override
protected void onPreExecute ( )
{
//starting the progress dialogue
pd.show();
}
#Override
protected Void doInBackground (Void... params)
{
//fetch data here
...
...
return null;
}
#Override
protected void onPostExecute (Void result)
{
//set adapter here
...
...
//dismissing the progress dialogue
pd.dismiss();
}
}
In my experience i have so many problems with async runs and UI so now always separate the stuff trying to place the "responsibilities" in each place. So i do something like this:
Create my Async class with the process i want to do and nothing that transform the UI in it
Create a function in UI thread that modify the UI when async task finish, something like OnAsyncTaskComplete(Object response)
Keep communicated the threads
public class MyActivity extends Activity {
private static MyAsyncClass backgroundTask;
private static ProgressDialog pleaseWaitDialog;
//......activity stuff.......
#Override
public void onPause()
{
super.onPause();
//Get rid of progress dialog in the event of a screen rotation or other state change. Prevents a crash.
if (pleaseWaitDialog != null)
pleaseWaitDialog.dismiss();
}
//Function to avoid lose the async thread if the app interrupts (phone rotation, incoming call, etc) RECOMENDED TO HANDLE THIS!!
//Sets the current state after app resume
#Override
public void onResume()
{
super.onResume();
//If there is a background task set it to the new activity
if ((backgroundTask != null) && (backgroundTask.getStatus() == Status.RUNNING))
{
if (pleaseWaitDialog != null)
pleaseWaitDialog.show();
backgroundTask.setActivity(this);
}
}
}
//Logic business after the web service complete here
//Do the thing that modify the UI in a function like this
private void onTaskCompleted(Object _response)
{
//For example _response can be a new adapter
MyList.setAdapter((BaseAdapter)_response);
//or can be a list to create the new adapter
MyList.setAdapter(new MyAdapter(this, (ArrayList<String>)_response));
//or can be anything you want, just try to make here the things that you need to change the UI
}
/**
* Class that handle the async task
*/
public class MyAsyncClass extends AsyncTask<Void, Void, Object>
{
//Maintain attached activity for states change propose
private MyActivity activity;
//Keep the response of the async task
private Object _response;
//Flag that keep async task completed status
private boolean completed;
//Constructor
private MyAsyncClass(MyActivity activity) {
this.activity = activity;
}
//Pre execution actions
#Override
protected void onPreExecute() {
//Start the splash screen dialog
if (pleaseWaitDialog == null)
pleaseWaitDialog= ProgressDialog.show(activity.this,
"PLEASE WAIT",
"Getting results...",
false);
}
//Execution of the async task
protected Object doInBackground(Object...params)
{
//return the thing you want or do want you want
return new ArrayList();
}
//Post execution actions
#Override
protected void onPostExecute(Object response)
{
//Set task completed and notify the activity
completed = true;
_response = response;
notifyActivityTaskCompleted();
//Close the splash screen
if (pleaseWaitDialog != null)
{
pleaseWaitDialog.dismiss();
pleaseWaitDialog = null;
}
}
//Notify activity of async task completion
private void notifyActivityTaskCompleted()
{
if ( null != activity ) {
activity.onTaskCompleted(_response);
}
}
//for maintain attached the async task to the activity in phone states changes
//Sets the current activity to the async task
public void setActivity(MyActivity activity)
{
this.activity = activity;
if ( completed ) {
notifyActivityTaskCompleted();
}
}
}
}
Hope its help you
First of all you cannot set the adapter in the doInBackground
follow this design:
private class LoadMoreVehicals extends AsyncTask<Object, Integer, Object>
{
private ArrayList<Country> countries;
#Override
protected void onPreExecute() {
progressBar = ProgressDialog.show(RegistrationScreen.this, "","Loading...");
progressBar.setIndeterminate(true);
progressBar.setIndeterminateDrawable(getResources().getDrawable(R.anim.progressbar_handler));
super.onPreExecute();
}
#Override
protected Object doInBackground(Object... params) {
String countryUrl = ConstantURL.COUNTRY_URL;
countries = getCounty(countryUrl);
return null;
}
#Override
protected void onProgressUpdate(Integer... values) {
progressBar.getProgress();
}
#Override
protected void onPostExecute(Object result) {
countrySpinner.setAdapter(new MyCustomSpinnerAdapter(RegistrationScreen.this,R.layout.spinner_dropdown,countries));
progressBar.dismiss();
Log.e("Im in onPostExecute", "");
super.onPostExecute(result);
}
}

Categories

Resources