@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // connect server User user = BmobUser.getCurrentUser(this, User.class); BmobIM.connect( user.getObjectId(), new ConnectListener() { @Override public void done(String uid, BmobException e) { if (e == null) { Logger.i("connect success"); // 服务器连接成功就发送一个更新事件,同步更新会话及主页的小红点 EventBus.getDefault().post(new RefreshEvent()); } else { Logger.e(e.getErrorCode() + "/" + e.getMessage()); } } }); // 监听连接状态,也可通过BmobIM.getInstance().getCurrentStatus()来获取当前的长连接状态 BmobIM.getInstance() .setOnConnectStatusChangeListener( new ConnectStatusChangeListener() { @Override public void onChange(ConnectionStatus status) { toast("" + status.getMsg()); } }); // 解决leancanary提示InputMethodManager内存泄露的问题 IMMLeaks.fixFocusedViewLeak(getApplication()); }
@Override protected void onResume() { super.onResume(); // 显示小红点 checkRedPoint(); // 进入应用后,通知栏应取消 BmobNotificationManager.getInstance(this).cancelNotification(); }
@Override protected void initView() { super.initView(); mTabs = new Button[3]; mTabs[0] = btn_conversation; mTabs[1] = btn_contact; mTabs[2] = btn_set; mTabs[0].setSelected(true); initTab(); }
@Override protected void onDestroy() { super.onDestroy(); // 清理导致内存泄露的资源 BmobIM.getInstance().clear(); }