간단한 작업을하고 싶습니다.하지만 Google 검색에서 표현할 수 없습니다.자바 콜백 함수가 매개 변수로 사용됩니다.
class RequestTask extends AsyncTask<String, String, String> {
final MyCallbackInterface callback;
RequestTask(MyCallbackInterface callback) {
this.callback = callback;
}
@Override
protected String doInBackground(String... uri) {
...
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
callback.onTaskFinished(result);
}
}
interface MyCallbackInterface {
void onTaskFinished(String result);
}
그래서, 내가 작업이 종료 될 때 실행할 콜백으로 작업이 : 그래서, 나는이 같은 비동기 작업이 여기 ^^
온다. (방법, 예 경우?)
: 같은 것을 할 수 있습니다, 대신 콜백과 같은 "인라인"기능이있는의,class Program {
public void DoAsyncRequest(String stringUrl, MyCallbackInterface callback) {
new RequestTask(callback).execute(stringUrl);
}
public static void Main(){
DoAsyncRequest("http://toto.com", new MyCallbackInterface() {
@Override
public void onDownloadFinished(String result) {
//do something ...
}
});
}
}
을하지만 : 이제
I는 다음과 같이 호출 할 수 있습니다
class Program {
public void DoAsyncRequest(String stringUrl, MyCallbackInterface callback) {
new RequestTask(callback).execute(stringUrl);
}
public static void Main(){
DoAsyncRequest("http://toto.com", MyCallBack);
}
private void MyCallBack(string result){
//do something
}
}
감사합니다. 콜백이 객체의 하나가 될 것으로 예상된다과 같이
private void MyCallBack(string result){
//do something
}
할 수 없습니다
private static class MyCallback implements MyCallbackInterface {
@Override
public void onDownloadFinished(String result) {
//do something ...
}
}
다음
DoAsyncRequest("http://toto.com", new MyCallBack());
를 사용하여 호출 :