Какой самый простой способ вернуть токен Firebase в этой асинхронной задаче? ⇐ JAVA
-
Гость
Какой самый простой способ вернуть токен Firebase в этой асинхронной задаче?
I need to modify an 8 year old, very bound code. In the old code I didn't have to wait for the async result, so I could work with it easily, but now I have to wait for it because of another async task.
Old version:
public class AsyncGetToken extends MyAsyncTask { public AsyncGetToken(Context context, TaskResponseListener taskResponseListener, String message) { super(context, taskResponseListener, message); } @Override protected Response executeTask(JSONObject json) throws Exception { if (FirebaseInstanceId.getInstance().getToken() == null) { sendErrorResponse(new Error(getType(), ERR_CODE, ERR_LOG)); return null; } return new Response(getFunction(), id, FirebaseInstanceId.getInstance().getToken(), null); } @Override protected String getFunction() { return ASYNC_FUNC; } @Override protected String getType() { return ASYNC_TYPE; } } New version:
public class AsyncGetToken extends MyAsyncTask { public AsyncGetToken(Context context, TaskResponseListener taskResponseListener, String message) { super(context, taskResponseListener, message); } @Override protected Response executeTask(JSONObject json) throws Exception { FirebaseMessaging.getInstance().getToken() .addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { // Get new FCM registration token String token = task.getResult(); //now i have to return a new Response with the token but obviously I can't send it back }); } @Override protected String getFunction() { return ASYNC_FUNC; } @Override protected String getType() { return ASYNC_TYPE; } } So what's the easiest way?
Источник: https://stackoverflow.com/questions/781 ... async-task
I need to modify an 8 year old, very bound code. In the old code I didn't have to wait for the async result, so I could work with it easily, but now I have to wait for it because of another async task.
Old version:
public class AsyncGetToken extends MyAsyncTask { public AsyncGetToken(Context context, TaskResponseListener taskResponseListener, String message) { super(context, taskResponseListener, message); } @Override protected Response executeTask(JSONObject json) throws Exception { if (FirebaseInstanceId.getInstance().getToken() == null) { sendErrorResponse(new Error(getType(), ERR_CODE, ERR_LOG)); return null; } return new Response(getFunction(), id, FirebaseInstanceId.getInstance().getToken(), null); } @Override protected String getFunction() { return ASYNC_FUNC; } @Override protected String getType() { return ASYNC_TYPE; } } New version:
public class AsyncGetToken extends MyAsyncTask { public AsyncGetToken(Context context, TaskResponseListener taskResponseListener, String message) { super(context, taskResponseListener, message); } @Override protected Response executeTask(JSONObject json) throws Exception { FirebaseMessaging.getInstance().getToken() .addOnCompleteListener(new OnCompleteListener() { @Override public void onComplete(@NonNull Task task) { // Get new FCM registration token String token = task.getResult(); //now i have to return a new Response with the token but obviously I can't send it back }); } @Override protected String getFunction() { return ASYNC_FUNC; } @Override protected String getType() { return ASYNC_TYPE; } } So what's the easiest way?
Источник: https://stackoverflow.com/questions/781 ... async-task
Мобильная версия