Skip to content

Commit

Permalink
Improve AppManager
Browse files Browse the repository at this point in the history
  • Loading branch information
JessYanCoding committed Sep 2, 2017
1 parent 34deb02 commit a4dedba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.net.ParseException;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
Expand All @@ -20,7 +19,6 @@
import com.jess.arms.di.module.GlobalConfigModule;
import com.jess.arms.http.GlobalHttpHandler;
import com.jess.arms.http.RequestInterceptor;
import com.jess.arms.integration.AppManager;
import com.jess.arms.integration.ConfigModule;
import com.jess.arms.utils.ArmsUtils;
import com.squareup.leakcanary.LeakCanary;
Expand Down Expand Up @@ -183,18 +181,17 @@ public void onCreate(Application application) {
//leakCanary内存泄露检查
ArmsUtils.obtainAppComponentFromContext(application).extras().put(RefWatcher.class.getName(), BuildConfig.USE_CANARY ? LeakCanary.install(application) : RefWatcher.DISABLED);
//扩展 AppManager 的远程遥控功能
ArmsUtils.obtainAppComponentFromContext(application).appManager().setHandleListener(new AppManager.HandleListener() {
@Override
public void handleMessage(AppManager appManager, Message message) {
switch (message.what) {
//case 0:
//do something ...
// break;
}
ArmsUtils.obtainAppComponentFromContext(application).appManager().setHandleListener((appManager, message) -> {
switch (message.what) {
//case 0:
//do something ...
// break;
}
});
//Usage:
//AppManager.post(message); like EventBus
//Message msg = new Message();
//msg.what = 0;
//AppManager.post(msg); like EventBus
}

@Override
Expand Down
4 changes: 3 additions & 1 deletion arms/src/main/java/com/jess/arms/integration/AppManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* 用于管理所有 activity,和在前台的 activity
* 可以通过直接持有 AppManager 对象执行对应方法
* 也可以通过 eventbus post 事件,远程遥控执行对应方法
* 也可以通过 {@link #post(Message)} ,远程遥控执行对应方法,用法和 EventBus 类似
* <p>
* Created by jess on 14/12/2016 13:50
* Contact with jess.yan.effort@gmail.com
Expand Down Expand Up @@ -113,6 +113,7 @@ public void setHandleListener(HandleListener handleListener) {

/**
* 通过此方法远程遥控 AppManager ,使 {@link #onReceive(Message)} 执行对应方法
*
* @param msg
*/
public static void post(Message msg) {
Expand Down Expand Up @@ -166,6 +167,7 @@ public void startActivity(Class activityClass) {
public void release() {
EventBus.getDefault().unregister(this);
mActivityList.clear();
mHandleListener = null;
mActivityList = null;
mCurrentActivity = null;
mApplication = null;
Expand Down

0 comments on commit a4dedba

Please sign in to comment.