小编Hid*_*oid的帖子

EventBus和RxJava有什么区别?

我对android中的EventBus和RxJava之间的区别感到困惑.我需要为我的问题实现其中一个关于在完成一些更改时通知某些组件的问题,以便他们可以更新其状态.
另外,我读到EventsBus已经被RxJava弃用了,我不知道这些信息是否属实.

android event-bus rx-java

50
推荐指数
2
解决办法
1万
查看次数

错误重复输入:com/google/android/gms/location/places/zzj.class

我尝试运行项目时遇到此错误:

错误:任务':app:transformClassesWithJarMergingForDebug'的执行失败.com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/google/android/gms/location/places/zzj.class

这是我正在使用的build.gradle文件:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.2'
        classpath 'io.realm:realm-gradle-plugin:0.89.1'
    }
}
apply plugin: "com.android.library"
apply plugin: "realm-android"

repositories {
    jcenter()
}

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.3'

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 22
    }

    buildTypes {
        debug {
            minifyEnabled false
        }
        release {
            minifyEnabled false
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile "com.android.support:appcompat-v7:23.1.1"
    compile "com.android.support:cardview-v7:23.1.1"
    compile "com.android.support:recyclerview-v7:23.1.1"
    compile "com.android.support:design:23.1.1"
    compile "com.squareup.okhttp3:okhttp:3.1.2"
    compile ('com.facebook.android:facebook-android-sdk:4.9.0')
        { exclude group: 'com.android.support' }
    compile ('com.googlecode.libphonenumber:libphonenumber:7.2.2') …
Run Code Online (Sandbox Code Playgroud)

android google-places-api google-play-services android-studio

11
推荐指数
1
解决办法
1万
查看次数

服务泄露了最初绑定在这里的ServiceConnection

我正在使用启动IntentService的BraodCastReceiver.Everythings看起来很好用,但是我得到了这个错误,我不知道它的来源:

android.app.ServiceConnectionLeaked: Service     com.merchantech.app.smartdiscount.MyIntentService has leaked ServiceConnection  com.clover.sdk.v3.order.OrderConnector@535008f4 that was originally bound here
        at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:969)
        at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:863)
        at android.app.ContextImpl.bindService(ContextImpl.java:1426)
        at android.app.ContextImpl.bindService(ContextImpl.java:1415)
        at android.content.ContextWrapper.bindService(ContextWrapper.java:473)
        at com.clover.sdk.v1.ServiceConnector.connect(ServiceConnector.java:119)
        at com.clover.sdk.v1.ServiceConnector.waitForConnection(ServiceConnector.java:148)
        at com.clover.sdk.v1.ServiceConnector.execute(ServiceConnector.java:209)
        at com.clover.sdk.v3.order.OrderConnector.getOrder(OrderConnector.java:153)
        at com.merchantech.app.smartdiscount.MyIntentService.onHandleIntent(MyIntentService.java:41)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:137)
        at android.os.HandlerThread.run(HandlerThread.java:60)
Run Code Online (Sandbox Code Playgroud)

这是我的BrodcastReceiver类:

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals("com.test.intent.action.LINE_ITEM_ADDED")) {
            Intent i = new Intent(context, MyIntentService.class);
            context.startService(i);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的IntentService类:

public class MyIntentService extends IntentService { …
Run Code Online (Sandbox Code Playgroud)

service android broadcastreceiver intentservice

6
推荐指数
2
解决办法
2万
查看次数

如何在片段中添加菜单?

当我使用片段时,我没有在ActionBar中获得菜单.尽管执行了onCreateOptionsMenu()方法,但我不知道代码的问题在哪里.这是我正在使用的代码:

public class LesAvis extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    setHasOptionsMenu(true);
    View rootView = inflater.inflate(R.layout.avis, container,false);
    ListView listeAvis = (ListView) rootView.findViewById(R.id.listView);
    return rootView;

}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.my_menu, menu);
    super.onCreateOptionsMenu(menu,inflater);
}

}
Run Code Online (Sandbox Code Playgroud)

但是,当我使用这部分代码来实现onCreateOptionsMenu()方法时,我得到了我想要的东西(我的操作栏中的菜单):

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.add("Compte")
    .setIcon(R.drawable.ic_compte)
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.add("Compte")
    .setIcon(R.drawable.ic_historique)
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.add("Compte")
    .setIcon(R.drawable.ic_param)
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
Run Code Online (Sandbox Code Playgroud)

java android menu android-fragments

5
推荐指数
1
解决办法
7361
查看次数