作成中のアプリで問題が発生しています。基本的には、アプリケーションを初めて開こうとするとクラッシュし、その後は正常に終了します。混乱する部分は、Google Playからアプリをダウンロードするときにのみ発生します。 Androidスタジオからアプリをスマートフォンに直接ロードするとエラーは発生しません。プロダクションリリースでのアプリの読み込み時にRuntimeExceptionが発生する
java.lang.RuntimeException:
at android.app.ActivityThread.handleReceiver (ActivityThread.java:3290)
at android.app.ActivityThread.-wrap20 (ActivityThread.java)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1715)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:154)
at android.app.ActivityThread.main (ActivityThread.java:6682)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1410)
Caused by: java.lang.ClassNotFoundException:
at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass (ClassLoader.java:380)
at java.lang.ClassLoader.loadClass (ClassLoader.java:312)
at android.app.ActivityThread.handleReceiver (ActivityThread.java:3285)
この問題を調査した後、私は人々がデバイスのキャッシュをクリアすると言います。これで問題は解決しましたが、それはアプリを拭き取り、それ以降は正常に動作します。最初のインストールはまだクラッシュします。これは複数のデバイスで発生しましたが、デバッグ中は再現できません。私の唯一の考えは、setContentView()を呼び出した直後にonCreate()にこのコードがあることです。
Intent intent = new Intent(this, NotificationListener.class);
startService(intent);
bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
NotificationListener.classはNotificationListenerServiceを継承します。最初の打ち上げを除いてすべてが素晴らしいです。
UPDATE
は、ここで私はAndroidManifestでサービスを設定する方法である:ここでは
<service android:name=".NotificationListener"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
は私NotificationListenerServiceの簡易版である:ここで
public class NotificationListener extends NotificationListenerService
{
private IBinder mBinder = new LocalBinder();
@Override
public void onNotificationPosted(StatusBarNotification sbn)
{
super.onNotificationPosted(sbn);
// custom code
}
@Override
public void onNotificationRemoved(StatusBarNotification sbn)
{
super.onNotificationRemoved(sbn);
}
@Override
public IBinder onBind(Intent intent)
{
if (SERVICE_INTERFACE.equals(intent.getAction()))
return super.onBind(intent);
else return mBinder;
}
public class LocalBinder extends Binder
{
public NotificationListener getService()
{
return NotificationListener.this;
}
}
}
はのためServiceConnectionですバインダー:
private ServiceConnection serviceConnection = new ServiceConnection()
{
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder)
{
NotificationListener.LocalBinder localBinder = (NotificationListener.LocalBinder) iBinder;
notificationListener = localBinder.getService();
bound = true;
// code to call custom function in NotificationListener class
}
@Override
public void onServiceDisconnected(ComponentName componentName)
{
notificationListener = null;
bound = false;
}
};
私はすべてのバインディングコードを削除してサービスを開始すれば、すべてが必要なように実行されるため、これはサービスのバインドに関する問題であることがわかります。このエラーが発生するのはバインドコードを追加するときだけです。
もし私がプロガードなしでapkファイルを作成しようとしていますか? – kimkevin
@KimKevinその場合、私はそれを削除し、私のアプリのベータ版をアップロードし、まだ起動時に同じエラーが発生しました – saboehnke
はい、それはfalseとして設定されているか、ClassNotFoundExceptionが発生したため...登録しましたか? NotificationListenerServiceからAndroidManiへfest.xml? – kimkevin