Click here to Skip to main content
15,358,528 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?.

//AsyncTask Class//
protected class Check extends AsyncTask<String, JSONObject, Boolean> { 
		String cc=null;
		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);
			} catch (Exception e) {
				Log.d("Check", e.getMessage());
			return codeAuth;

		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();

     public void ok(View view){

Thanks a lots
Updated 24-Jun-21 4:15am
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?
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.[^][^]
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.

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