-
-
Save yongjhih/3389f686801d08bb3a13e2b406ba87c3 to your computer and use it in GitHub Desktop.
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 void login(final String mac, final String devicesOs, final String appVersion, String userAcct, String userPwd, String memType) { | |
getSubscription().add(ApiClient.getInstance().personLogin(mac, devicesOs, appVersion, userAcct, userPwd, memType) | |
.subscribeOn(Schedulers.newThread()) // (1) | |
.observeOn(AndroidSchedulers.mainThread()) // (2) | |
.flatMap(new Func1<PersonLogin, Observable<PersonData>>() { | |
@Override | |
public Observable<PersonData> call(PersonLogin personLogin) { | |
// main thread | |
return ApiClient.getInstance().queryPersonData(mac, devicesOs, appVersion, personLogin.getUId(), personLogin.getSessionId()).subscribeOn(Schedulers.newThread()); | |
} | |
}) | |
.doOnSubscribe(new Action0() { | |
@Override | |
public void call() { | |
getView().showLoading(); | |
} | |
}) | |
.subscribe(new Observer<PersonData>() { | |
@Override | |
public void onCompleted() { | |
} | |
@Override | |
public void onError(Throwable e) { | |
// 此處拿到 main thread | |
Log.d(TAG, Thread.currentThread().getName()); | |
// 如果call 如 Toast or e.getMessage(); | |
// 此處噴 Can't create handler inside thread that has not called Looper.prepare() | |
} | |
@Override | |
public void onNext(PersonData personData) { | |
// 我想在此處也處理Ui所以切AndroidSchedulers.mainThread() (2)處 | |
} | |
})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment