Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I can't get "result"boolean value in onPostExecute. there's way to get result value "0,1" success or not to use in OK button. There's the way?.

Java
//AsyncTask Class//
protected class Check extends AsyncTask<String, JSONObject, Boolean> { 
		String cc=null;
		
		@Override
		protected Boolean doInBackground(String... params) {
			RestAPI api = new RestAPI();
			boolean codeAuth = false;
			try {
				JSONObject jsonObj = api.CodeAuthentication(params[0]);
				JSONParser parser = new JSONParser();
				codeAuth = parser.parseCodeAuth(jsonObj);
				cc=params[0];	
			} catch (Exception e) {
				Log.d("Check", e.getMessage());
			}
			return codeAuth;
		}

		@Override
		protected void onPostExecute(Boolean result) {//***HERE
			if (result) {
				Toast.makeText(getApplicationContext(), "Success!!",Toast.LENGTH_HORT).show();
			}
			else {
				Toast.makeText(getApplicationContext(), "Error!!",Toast.LENGTH_SHORT).show();
			}
		}
}

 //BUTTON//
     public void ok(View view){
        
     }	


Thanks a lots
Posted
Updated 24-Jun-21 4:15am
v2
Comments
Sergey Alexandrovich Kryukov 28-Aug-14 8:57am    
The question makes no sense. It is not related to any buttons, and you always get result value, because this is passed as a parameter. Do you have onPostExecute called at all?
—SA
Eerven 28-Aug-14 22:41pm    
Yeah I know but just want the result of this protected class to check something outside in button...

I think, you could not get return value from asynctask instance but there are many ways to process last performance according to ret value of asynctask.

Very simple ways is to use callback. See here.
http://y-sugasawa.blogspot.jp/2012/08/androidasynctask.html[^]
http://android.keicode.com/basics/async-asynctask.php[^]
 
Share this answer
 
You can retreive the return value of protected Boolean doInBackground() by calling the get() method of AsyncTask class :

AsyncTaskClassName task = new AsyncTaskClassName();
bool result = task.execute(param1,param2......).get();
But be careful of the responsiveness of the UI, because get() waits for the computation to complete and will block the UI thread.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900