Android 异常点滴汇总
1.Caused by: Java.lang.RuntimeException: Unknown animation name: objectAnimator,或者 runtimeexception: Unknow animator name: translate
异常原因:因为Fragment导错包导致;
调用 ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right); 加载动画,会触发FragmentManager类中的loadAnimation方法,而该方法加载的动画标签类型在不同的包中支持的标签不一样。可以看下源码。android.app.Fragment中支持的动画标签为:objectAnimator 和 animator 和 set 而 android.support.v4.app.Fragment中支持的动画标签为 set,alpha,scale,translate,rotate.所以如果你的Fragment是应该使用对应支持的动画。
2.在调用onConfigurationchanged();不执行:
原因:配置不完全。如果设置了android:targetSdkVersion ,记得加上screenSize。
完整配置如下: android:configChanges="orientation|keyboard|keyboardHidden|screenSize|layoutDirection"
3.隐式启动Service时warming:Implicit intents with startService are not safe: XXX
原因:
4.在蓝牙开发过程中:
Android5.0后,其中有个特性就是Service Intent must be explitict,也就是说从Lollipop开始,service服务必须采用显示方式启动。源码是这样写的(源码位置:sdk/sources/android-21/android/app/ContextImpl.Java)解决方法:
1.设置Action和packageName:(此方式是google官方推荐使用的解决方法。参考:http://developer.android.com/goo ... tml#billing-service)
- Intent mIntent = new Intent();
- mIntent.setAction("XXX.XXX.XXX");//你定义的service的action
- mIntent.setPackage(getPackageName());//这里你需要设置你应用的包名
- context.startService(mIntent);
- public static Intent getExplicitIntent(Context context, Intent implicitIntent) {
- // Retrieve all services that can match the given intent
- PackageManager pm = context.getPackageManager();
- List<ResolveInfo> resolveInfo = pm.queryIntentServices(implicitIntent, 0);
- // Make sure only one match was found
- if (resolveInfo == null || resolveInfo.size() != 1) {
- return null;
- }
- // Get component info and create ComponentName
- ResolveInfo serviceInfo = resolveInfo.get(0);
- String packageName = serviceInfo.serviceInfo.packageName;
- String className = serviceInfo.serviceInfo.name;
- ComponentName component = new ComponentName(packageName, className);
- // Create a new intent. Use the old one for extras and such reuse
- Intent explicitIntent = new Intent(implicitIntent);
- // Set the component to be explicit
- explicitIntent.setComponent(component);
- return explicitIntent;
- }
- 调用方式如下:
- Intent mIntent = new Intent();
- mIntent.setAction("XXX.XXX.XXX");
- Intent eintent = new Intent(getExplicitIntent(mContext,mIntent));
- context.startService(eintent);