Created
August 14, 2018 15:15
-
-
Save KanshuYokoo/3a682d7917bfdb1528199a16efda6d33 to your computer and use it in GitHub Desktop.
android async
This file contains hidden or 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
public class StartActivity extends AppCompatActivity implements ResultHandleInterface { | |
private ProgressBar mCycler; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
new APITask(this).execute(place); | |
} | |
@Override | |
public Boolean APIrun(String... params) { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
mCycler.setVisibility(View.VISIBLE); | |
} | |
}); | |
Boolean result = false; | |
try { | |
//TODO API request | |
} catch (IOException e) { | |
//todo API network error | |
} | |
return result; | |
} | |
@Override | |
public void APISuccess() { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
mCycler.setVisibility(View.INVISIBLE); | |
} | |
}); | |
} | |
@Override | |
public void APIFailed() { | |
runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
mCycler.setVisibility(View.INVISIBLE); | |
} | |
}); | |
} | |
private class APITask extends AsyncTask<String, Integer, Boolean> { | |
private ResultHandleInterface listenerLogin; | |
public settingDataTask(ResultHandleInterface listener) { | |
this.listenerLogin = listener; | |
} | |
@Override | |
protected Boolean doInBackground(String... userCred) { | |
boolean result = listenerLogin.APIrun(userCred); | |
return result; | |
} | |
@Override | |
protected void onProgressUpdate(Integer... progress) { | |
} | |
@Override | |
protected void onPostExecute(Boolean result) { | |
if (result) { | |
listenerLogin.APISuccess(); | |
} else { | |
listenerLogin.APIFailed(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment