Exemplo n.º 1
0
 @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());
 }
Exemplo n.º 2
0
 private void checkRedPoint() {
   int count = (int) BmobIM.getInstance().getAllUnReadCount();
   if (count > 0) {
     iv_conversation_tips.setVisibility(View.VISIBLE);
   } else {
     iv_conversation_tips.setVisibility(View.GONE);
   }
   // 是否有好友添加的请求
   if (NewFriendManager.getInstance(this).hasNewFriendInvitation()) {
     iv_contact_tips.setVisibility(View.VISIBLE);
   } else {
     iv_contact_tips.setVisibility(View.GONE);
   }
 }
Exemplo n.º 3
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   // 清理导致内存泄露的资源
   BmobIM.getInstance().clear();
 }