Passing a string from AsyncTask to onCreate or other Activities - android

I am trying to query JSON data on a background thread using AsyncTask and use one of the values from the query in onCreate of the same Activity. How should I do this? Should I use intents or is there a more intuitive and better way of doing it?
In my code below, I am trying to pull the youtube ID using an AsyncTask out of an online database. It works because when I log the value inside the AsyncTask, the correct youtube ID is shown. But I need to use this ID in onCreate so that I can use it to create the full youtube URL. How can I pass the youtube ID string from doInBackground to onCreate? The id is stored in the variable youtubeId
//Activity needs added to manifest.
public class DetailsActivity extends AppCompatActivity {
//LOG tag for debugging
private static final String TAG = "GalleryActivity";
String youtubeIdCode;
//Override on Create and set contentView to new activity_details layout.
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
//Log for debugging so we can tell if activity started successfully.
Log.d(TAG, "onCreate: started.");
loadMovieData();
Intent intent = getIntent();
Movie movie = intent.getParcelableExtra("movie");
String image = movie.getMoviePoster();
String title = movie.getTitle();
String releaseDate = movie.getDate();
String voteAverage = movie.getVoteAverage();
String plot = movie.getPlot();
ImageView poster = findViewById(R.id.details_image);
Picasso.with(this).load(image).into(poster);
TextView name = findViewById(R.id.details_title);
name.setText((getResources().getString(R.string.movie_title)) + " " + title);
TextView dateRelease = findViewById(R.id.details_release_date);
dateRelease.setText((getResources().getString(R.string.release_date)) + " " + releaseDate);
TextView averageVote = findViewById(R.id.details_voter_average);
averageVote.setText((getResources().getString(R.string.vote_average)) + " " + voteAverage);
TextView moviePlot = findViewById(R.id.details_plot);
moviePlot.setText((getResources().getString(R.string.plot)) + " " + plot);
ImageView watchTrailer = findViewById(R.id.imageView);
// watchTrailer.setOnClickListener(new View.OnClickListener() {
// #Override
// public void onClick(View v) {
// Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(trailerUrl.toString()));
// Log.v("OnClick URL",trailerUrl.toString());
// startActivity(intent);
// }
// });
}
public class FetchTrailer extends AsyncTask<String, Void, Void> {
#Override
protected Void doInBackground(String... strings) {
final String YOUTUBE_ID = "id";
final String RESULTS = "results";
String youtubeId = " ";
Intent intent = getIntent();
Movie movie = intent.getParcelableExtra("movie");
String id = movie.getID();
final URL trailerUrl = NetworkUtils.buildUrlTrailer(id);
Log.v("Built trailer url", trailerUrl.toString());
try {
String jsonResponse = NetworkUtils.getReponseFromHttpUrl(trailerUrl);
JSONObject moviesObject = new JSONObject(jsonResponse);
JSONArray resultsArray = moviesObject.getJSONArray(RESULTS);
for(int i = 0; i < resultsArray.length(); i ++){
JSONObject movieObject = resultsArray.getJSONObject(i);
youtubeId = movieObject.getString(YOUTUBE_ID);
Log.v("youtubeid", youtubeId);
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}
//Tell the new method to get the data based on the search term within the url.
private void loadMovieData() {
//If there is a network connection, fetch the data.
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
if (isConnected) {
new FetchTrailer().execute();
} else {
Toast toast = Toast.makeText(this, getString(R.string.no_internet_toast), Toast.LENGTH_LONG);
toast.show();
}
}
}

Seems youtubeId is a pre-requisite for your DetailsActivity. So we would need youtubeId prior to DetailsActivity initialization.
In your previous activity from where user can be landed to DetailsActivity , before calling startActivity(intent) call your
loadMovieData()
method as is, you would have to declare method in prior activity. After that pass the youtubeId through intent to DetailsActivity, and you can retrieve value in oncreate():
Intent myIntent = new Intent(CurrentActivity.this,
NextActivity.class);
myIntent.putExtra("youtubeId", value); //Optional parameters
CurrentActivity.this.startActivity(myIntent);
Extras are retrieved on the other side via:
#Override
protected void onCreate(Bundle savedInstanceState) {
Intent intent = getIntent();
String value = intent.getStringExtra("youtubeId"); //if it's a string you
stored.
}

You can use a Callback Listener to achieve this
public interface FetchTrailerListener {
public void onTrailerFetched(String youtubeId);
}
Make DetailsActivity to implement this. Pass this listener reference to asynctask when you are instantiating it.In this way from your postexecute notify the activity through this listener.
protected void onPostExecute( String youtubeId) {
fetchTrailerListenr.onTrailerFetched(youtubeId);
}

Related

Passing value from onPostExecute to onCreate

I have a query running to collect a youtube id from a database. The AsyncTask works and I get the piece of information but I can't pass it from onPostExecute to onCreate.
Here is what I have tried doing.
Make youtubeIdCode a global variable.
Run the query to get the id from the database.
Return the youtubeid in doInBackground.
Set youtubeIdCode = the result of doInBackground in onPostExecute.
Try calling the youtubeIdCode in onCreate to see if the result from onPostExecute passed to youtubeIdCode. This is where I have the issue. It is not passing from onPostExecute to onCreate. How can I pass it because in onCreate is where I will be needing the id to form a youtube url.
//Activity needs added to manifest.
public class DetailsActivity extends AppCompatActivity {
//LOG tag for debugging
private static final String TAG = "GalleryActivity";
String youtubeIdCode;
//Override on Create and set contentView to new activity_details layout.
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
//Log for debugging so we can tell if activity started successfully.
Log.d(TAG, "onCreate: started.");
youtubeIdCode = "";
loadMovieData();
String test = "The value is" + youtubeIdCode;
Log.v("youtube code test", test);
Intent intent = getIntent();
Movie movie = intent.getParcelableExtra("movie");
String image = movie.getMoviePoster();
String title = movie.getTitle();
String releaseDate = movie.getDate();
String voteAverage = movie.getVoteAverage();
String plot = movie.getPlot();
ImageView poster = findViewById(R.id.details_image);
Picasso.with(this).load(image).into(poster);
TextView name = findViewById(R.id.details_title);
name.setText((getResources().getString(R.string.movie_title)) + " " + title);
TextView dateRelease = findViewById(R.id.details_release_date);
dateRelease.setText((getResources().getString(R.string.release_date)) + " " + releaseDate);
TextView averageVote = findViewById(R.id.details_voter_average);
averageVote.setText((getResources().getString(R.string.vote_average)) + " " + voteAverage);
TextView moviePlot = findViewById(R.id.details_plot);
moviePlot.setText((getResources().getString(R.string.plot)) + " " + plot);
}
public class FetchTrailer extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... strings) {
final String YOUTUBE_ID = "id";
final String RESULTS = "results";
String youtubeId = " ";
Intent intent = getIntent();
Movie movie = intent.getParcelableExtra("movie");
String id = movie.getID();
final URL trailerUrl = NetworkUtils.buildUrlTrailer(id);
Log.v("Built trailer url", trailerUrl.toString());
try {
String jsonResponse = NetworkUtils.getReponseFromHttpUrl(trailerUrl);
JSONObject moviesObject = new JSONObject(jsonResponse);
JSONArray resultsArray = moviesObject.getJSONArray(RESULTS);
for(int i = 0; i < resultsArray.length(); i ++){
JSONObject movieObject = resultsArray.getJSONObject(i);
youtubeId = movieObject.getString(YOUTUBE_ID);
Log.v("youtubeid", youtubeId);
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return youtubeId;
}
#Override
protected void onPostExecute(String s) {
youtubeIdCode = s;
Log.v("onposttest", s);
}
}
//Tell the new method to get the data based on the search term within the url.
private void loadMovieData() {
//If there is a network connection, fetch the data.
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnectedOrConnecting();
if (isConnected) {
new FetchTrailer().execute();
} else {
Toast toast = Toast.makeText(this, getString(R.string.no_internet_toast), Toast.LENGTH_LONG);
toast.show();
}
}
}
I think you need to rethink the logic of the app. The main idea of using an AsyncTask is that the main thread would not block while the task is running.
This means onCreate() shouldn't wait for the AsyncTask to finish to continue it's execution, which is what you are implying that should happen.
The way to think your app, is that the URL setup you want to do with the youtube id, and any aditional processing should be trigged by onPostExecute() when the task is finished.
At a time of call asynTask you can do like that, may be it work i am not confident.
new FetchTrailer(){
#Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
}
}.execute()
Just do a setter of the var you need to put te value, then onPostExecute just call that setter function and pass the value of the var in the AsyncTask, and after that use a method to fetch the text on your widgets, if you do it before you pass the value it will be null.
Also try to do AsyncTask in a separate class
AsyncTask OnPostExecute
#Override
protected void onPostExecute(List<ListaLineal> superlistItems) {
super.onPostExecute(superlistItems);
activity.setSuperListItems(superlistItems); -> this retrieve the value of a list that I was using (I got the value of the list in doInBackground)
activity.setupData(); -> method for setting up data
}
In your case setupData will look similar to this
public void setupData(){
String image = movie.getMoviePoster();
String title = movie.getTitle();
String releaseDate = movie.getDate();
String voteAverage = movie.getVoteAverage();
String plot = movie.getPlot();
ImageView poster = findViewById(R.id.details_image);
Picasso.with(this).load(image).into(poster);
TextView name = findViewById(R.id.details_title);
name.setText((getResources().getString(R.string.movie_title)) + " " + title);
TextView dateRelease = findViewById(R.id.details_release_date);
dateRelease.setText((getResources().getString(R.string.release_date)) + " " + releaseDate);
TextView averageVote = findViewById(R.id.details_voter_average);
averageVote.setText((getResources().getString(R.string.vote_average)) + " " + voteAverage);
TextView moviePlot = findViewById(R.id.details_plot);
moviePlot.setText((getResources().getString(R.string.plot)) + " " + plot);
}

Passing data from first activities to a second , second activity to third activity in android

I have a total of 3 activites. I pass the data from the first activity :
Here's My AsyncTask parseResult method
private void parseResult(String result) {
try {
Log.d("MainActivity", "JSON Result : " + result);
JSONArray response = new JSONArray(result);
for (int i = 0; i < response.length(); i++)
{
JSONObject obj = response.getJSONObject(i);
String movie_d = obj.getString("newsD");
String movie_t = obj.getString("newsT");
String movie_i = obj.getString("newsI");
String movie_s_link=obj.getString("newsS");
String movie_youtube_link=obj.getString("youtubeLink");
Log.d("movie_youtube_link","JSON Result : " + result);
String movie_rev_r=obj.getString("reviewR");
Log.d("documentName","JSON Result : " + result);
Newspojo rev_gd = new Newspojo();
rev_gd.setNewsDescription(movie_dec);
rev_gd.setNewsT(movie_t);
rev_gd.setNewsI(movie_i);
rev_gd.setNewsS(movie_source_l);
rev_gd.setYoutubeLink(movie_youtube_link);
rev_gd.setReviewR(movie_rev_r);
revData.add(rev_gd);
}
} catch (JSONException e) {
e.printStackTrace();
}
In my first activity I am displaying a ListView. When I click a list item at current position i am displaying some fields in Activity 2
I send bundle data when i click a list position. Here's my onClick listener in list position
FirstActivity
reviewlist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
Intent intent = new Intent(getActivity(), Movie_rev_fulldis_activity.class);
intent.putExtra("mov_pos", position + "");
startActivity(intent);
}
});
return rootview;
}
Here my position OnClick was working fine. I'm trying to display some fields in Second Activity
Second Activity:
Here i pass some values it was displaying fine my problem is when i bundle my youtubeLink link to the third Activity. I am getting null values , I checked youtubeLink
value and I am getting it from the server and parsing it in TextView okay but my problem is when i bundle youtubeLink from second Activity to third Activity. I am getting null value.
static String youtubeLink;
youtubeLink=Reviews_update.revData.get(mov_pos).getYoutubeLink();
Toast.makeText(Movie_rev_fulldis_activity.this,
youtubeLink, Toast.LENGTH_LONG).show();
movie_t=(TextView)findViewById(R.id.revi_fulldes_movietitle);
rev_r=(TextView)findViewById(R.id.revi_fulldes_movierev_sitename);
movie_d=(TextView)findViewById(R.id.revi_fulldes_moviedisc_text);
//youtube video text static text (video)
youtube_text=(TextView)findViewById(R.id.revi_fulldes_movieyoutube_text);
movie_i=(ImageView)findViewById(R.id.revi_fulldes_movieImage);
//youtube image display id and imageView
youtube_image=(ImageView)findViewById(R.id.revi_fulldes_movieyoutubeImg);
youtube_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent youtube = new Intent(getApplicationContext(), PlayYouTube1st.class);
youtube.putExtra("youtubeLink", youtubeLink);
startActivity(youtube);
// Toast.makeText(Movie_rev_fulldis_activity.this,
// youtubeLink, Toast.LENGTH_LONG).show();
}
});
mov_pos = Integer.parseInt((getIntent().getExtras()).getString("mov_pos"));
movie_t.setText(Reviews_update.revData.get(mov_pos).getNewsT());
rev_r.setText(Reviews_update.revData.get(mov_pos).getReviewR());
movie_d.setText(Reviews_update.revData.get(mov_pos).getNewsD());
Picasso.with(getApplicationContext()).load((Reviews_update.revData.get(mov_pos)).getNewsI()).into(target);
}
Here's my ThirdActivity:
private YouTubePlayerView youTubeView;
String youLink;
Intent intent =getIntent();
youLink=intent.getStringExtra("youtubeLink");
youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
Toast.makeText(PlayYouTube1st.this,
youLink, Toast.LENGTH_LONG).show();
I have been stuck on this error for the past 2 days so could please someone help me find why youtubeLink is showing null values when passing it to 3rd Activity? Thank you!
Put below line
mov_pos = Integer.parseInt((getIntent().getExtras()).getString("mov_pos"));
above
youtubeLink=Reviews_update.revData.get(mov_pos).getYoutubeLink();

how to pass Json data in Android Adapter

Hello I am trying to pass Json Data from Adapter to another Activity
playb = (ImageButton) row.findViewById(R.id.playbtn);
playb.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Song newitem = getItem(position);
//long itemId = getItemId(position);
app = (myapplication) getContext().getApplicationContext();
app.setSong(item);
Intent intent1 = new Intent(getContext(), SongDetailedActivity.class);
intent1.putExtra("SongID", item.toString());
getContext().startActivity(intent1);
}
});
and my activity
Intent i = getActivity().getIntent();
hello = i.getIntExtra("SongID", 5);
Song event = app.getSongID(hello);
event.setSongID(hello);
In your activity,
Bundle bundle = getIntent().getExtras();
if(bundle != null && bundle.containsKey("SongID")){
String json = bundle.getString("SongID");
JSONObject jsonObject = new JSONObject(json);
//parse json from here...don't forget to handle JSONException
}
You can whether pass an integer value and catch it using i.getIntExtra()
or pass a String and catch using i.getStringExtra()
You can't put a string in intent and get it as integer, should has the same type.

Trouble passing ArrayList to another Activity

Good evening , I'm having trouble passing a ListView an Activity to another. The Activity code that passes to the other is the following called FiltrarImoveis.class :
for (int i = 0; i < jsonArray.length(); i++) {
Imovel imv = new Imovel();
JSONObject child = jsonArray.getJSONObject(i);
String finalidade=child.getString("finalidadeImovel");
String tipo = child.getString("tipoImovel");
String genero = child.getString("generoImovel");
String descricao = child.getString("descricaoImovel");
String responsavel = child.getString("responsavelImovel");
String telefoneResponsavel = child.getString("telefoneResponsavel");
String situacaoImovel = child.getString("situacaoImovel");
String valor = child.getString("valor");
imv.setFinalidade(finalidade);
imv.setTipo(tipo);
imv.setGenero(genero);
imv.setDescricao(descricao);
imv.setResponsavel(responsavel);
imv.setTelefoneResponsavel(telefoneResponsavel);
imv.setSituacao(situacaoImovel);
imv.setValor(valor);
listaImovel.add(imv);
}
} catch (JSONException e) {
e.printStackTrace();
}
//showParsedJSON.setText(output);
carregar(listaImovel);
}
}
}
public void carregar(ArrayList<Imovel> listaImovel){
Intent intent = new Intent(this,DetalhesImoveis.class);
intent.putExtra("lista",listaImovel);
startActivity(intent);
}
The class that inherits from the ListView is the following , call DetalhesImoveis.class :
private ListView lvImoveis;
ArrayList<Imovel> listaImoveis;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detalhes_imoveis);
listaImoveis = (ArrayList<Imovel>) getIntent().getSerializableExtra("lista");
lvImoveis = (ListView)findViewById(R.id.lvImoveis);
try {
ArrayAdapter<Imovel> adpImovel = new ArrayAdapter<Imovel>(DetalhesImoveis.this, android.R.layout.simple_list_item_1, listaImoveis);
lvImoveis.setAdapter(adpImovel);
//Log.v("LISTAiMOVEIS", "ELEMENTOS DA LISTA: " +listaImoveis.get(0).getDescricao().toString() );
}catch(Exception e){
Log.v("logs","ERROR CAUSED BY THE EXCEPTION LIST: "+e.toString());
}
}
We should not use putExtra()for ArrayList instead of that use putStringArrayListExtra() eg: public void carregar(ArrayList<Imovel> listaImovel){
Intent intent = new Intent(this,DetalhesImoveis.class);
intent.putStringArrayListExtra("lista",listaImovel);
and in DetalhesImoveis.class get the Arraylist like:listaImoveis = getIntent().getStringArrayListExtra("lista");
u can :
getIntent().putParcelableArrayListExtra(listaImovel)
Imovel need to implment Parcelable
u can look sth about Parcelable;
or :
AActvt Put list int application or a static var ;
BActvt get list from application or a static var;

Inner AsyncTask not updating member variables in outer class

I have an app that in one of it's Activities uses AsyncTask to call a method from another class that hooks up to a database to varify a user's login credentials. The Activity EntryActivity Has three member variable that need to be updated with the result of the AsyncTask, carerID, firstName and surName . When I first run the App all three variables are null but if i press the login button a second time the variables are set correctly and the app behaves as it should.
Is there a reason why the three member variables are not set correctly from onPostxecute in the first run of the app?
.
public class EntryActivity extends NfcBaseActivity{
private LoginWebservice loginWebservice;
private static final String TAG = EntryActivity.class.getSimpleName();
private Button login;
private EditText userName;
private EditText passwordPin;
NfcScannerApplication nfcscannerapplication;
public static final String CUSTOM_QRCODE_ACTION = "com.carefreegroup.QRCODE_ACTION";
private String carerID;
private String firstName;
private String surName;
private boolean isValidated = false;
#Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.entryscreen);
nfcscannerapplication = (NfcScannerApplication) getApplication();
loginWebservice = new LoginWebservice(this);
carerID = null;
firstName = null;
surName = null;
userName = (EditText)findViewById(R.id.username);
passwordPin = (EditText)findViewById(R.id.password);
login = (Button)findViewById(R.id.buttonlogin);
login.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
////////////get user's input///////////
String compId = "100";
String theUsername = userName.getText().toString();
String thePassword = passwordPin.getText().toString();
String loginType = "1";
String[] params = new String[]{compId, theUsername, thePassword, loginType};
//validate user Asynchonously on background thread
new AsyncValidateCarer().execute(params);
Log.e(TAG, "carerid =" + carerID + " firstname = " + firstName + " surnamee = " + surName);
DateTime now = new DateTime();
long loginTime = now.getMillis();
String fullName = firstName +" " + surName;
Log.e(TAG, "fullname = " + fullName);
if(carerID != null){
ContentValues loginValues = new ContentValues();
loginValues.putNull(LoginValidate.C_ID_INDEX);
loginValues.put(LoginValidate.C_CARER_ID, carerID);
loginValues.put(LoginValidate.C_COMP_ID, compId);
loginValues.put(LoginValidate.C_CARER_NAME, fullName);
loginValues.put(LoginValidate.C_PASSWORD, thePassword);
loginValues.put(LoginValidate.C_DATE_TIME, loginTime);
nfcscannerapplication.loginValidate.insertIntoCarer(loginValues);
Toast.makeText(
EntryActivity.this,
"Carer logged in to System",
Toast.LENGTH_LONG).show();
isValidated = true;
Intent intent = new Intent(EntryActivity.this,
NfcscannerActivity.class);
intent.setAction(CUSTOM_QRCODE_ACTION);
startActivity(intent);
}else{
Toast.makeText(
EntryActivity.this,
"Please check credentials",
Toast.LENGTH_LONG).show();
}
//////////////validate user/////////////////
}
});
Button changeUser = (Button)findViewById(R.id.buttonchangeuser);
changeUser.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.e(TAG, "change user button clicked");
nfcscannerapplication.loginValidate.deleteTableCarer();
Toast.makeText(
EntryActivity.this,
"Carer logged out",
Toast.LENGTH_LONG).show();
EntryActivity.this.onCreate(savedInstanceState);
}
});
}//end of onCreate
private void hideSoftKeyboard() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(passwordPin.getWindowToken(), 0);
}
private class AsyncValidateCarer extends AsyncTask<String, Void, ContentValues> {
#Override
protected ContentValues doInBackground(String... params) {
ContentValues cv = null;
try {
Log.e(TAG, "inside asynctask");
cv = loginWebservice.validateCarer(params[0], params[1], params[2], params[3]);
if (cv != null){
Log.e(TAG, "cv = not null!");
}
} catch (Exception e) {
e.printStackTrace();
}
return cv;
}
#Override
protected void onPostExecute(ContentValues result) {
Log.e(TAG, "inside onpostexecute");
EntryActivity.this.carerID = (String) result.get("carerID");
EntryActivity.this.firstName = (String) result.get("firstname");
EntryActivity.this.surName = (String) result.get("surname");
}
}
}
[update]
private class AsyncValidateCarer extends AsyncTask<String, Void, Void> {
#Override
protected Void doInBackground(String... params) {
ContentValues cv = null;
try {
Log.e(TAG, "inside doInBackground");
cv = loginWebservice.validateCarer(params[0], params[1], params[2], params[3]);
carerID = (String) cv.get("carerID");
firstName = (String) cv.get("firstname");
surName = (String) cv.get("surname");
if (cv != null){
Log.e(TAG, "cv = not null! and exiting doInBackground");
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
An AsyncTask will execute asynchronously so you have no guarantee that after the "execute" method call, the task is actually finished. My advice would be to move everything (or at least what is related to those fields) that are after "execute" call in "onPostExecute" method.
The reason why it seems the first click doesn't work and the second works, is that between the first "Login" click and the second one, you wait enough for the AsyncTask to finish. So when you click for the second time you see the results of the first execution. Please add some "Log" messeges in "onPostExecute" to understand what is going on.
Hope it helps:)
carerID = null;
firstName = null;
surName = null;
Remove the above there statements from the onCreate() method, as they have been initialized to their default values as they are in the Class Scope and are known as Instance Variables.

Categories

Resources