【发布时间】:2017-03-12 21:35:07
【问题描述】:
这里有一个类似的问题:Motion Recognition Manager and motion-Service in android
我问我的,因为有一条评论要求错误发生的代码并且没有提供代码。这是我在这里的第一个问题,所以我希望我没有做错或粗鲁的事情。
我正在开发一个应用程序,它解析 RSS 提要并具有用户可以更改的设置,例如背景颜色、文本颜色、用户名。这些设置保存在共享首选项中。
该应用在模拟器中完美运行。在之前的迭代中,在我添加共享偏好功能之前,我能够在我的个人三星 Galaxy s6 手机上运行该应用程序。现在,它无法在我的手机上运行。
我在ListView 中显示提要。设置从ListPreferences更改。
我的 logcat 看起来像这样:
10/30 10:33:34: Launching app
$ adb push C:\Users\Jennifer\AndroidStudioProjects\RSSAssignment7\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.example.jennifer.rssassignment7
$ adb shell pm install -r "/data/local/tmp/com.example.jennifer.rssassignment7"
pkg: /data/local/tmp/com.example.jennifer.rssassignment7
Success
$ adb shell am start -n "com.example.jennifer.rssassignment7/com.example.jennifer.rssassignment7.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Client not ready yet..Waiting for process to come online
Connected to process 14137 on device samsung-sm_g920w8-1215fc28c4943e05
W/System: ClassLoader referenced unknown path: /data/app/com.example.jennifer.rssassignment7-1/lib/arm64
D/InjectionManager: InjectionManager
D/InjectionManager: fillFeatureStoreMap com.example.jennifer.rssassignment7
I/InjectionManager: Constructor com.example.jennifer.rssassignment7, Feature store :{}
I/InjectionManager: featureStore :{}
W/ResourcesManager: getTopLevelResources: /data/app/com.example.jennifer.rssassignment7-1/base.apk / 1.0 running in com.example.jennifer.rssassignment7 rsrc of package com.example.jennifer.rssassignment7
W/ResourcesManager: getTopLevelResources: /data/app/com.example.jennifer.rssassignment7-1/base.apk / 1.0 running in com.example.jennifer.rssassignment7 rsrc of package com.example.jennifer.rssassignment7
W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
D/AbsListView: Get MotionRecognitionManager
E/MotionRecognitionManager: mSContextService = android.hardware.scontext.ISContextService$Stub$Proxy@8089b26
E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@53d367
E/MotionRecognitionManager: motionService = com.samsung.android.motion.IMotionRecognitionService$Stub$Proxy@53d367
Application terminated.
还有一个代码示例,ListPreferences 之一:
在preferences.xml中:
<ListPreference
android:title="Choose Your Text Color"
android:summary="We'll save your choice for next time."
android:key="color"
android:defaultValue="#000000"
android:entries="@array/colorArray"
android:entryValues="@array/colorValues" />
在array.xml中:
<!--color array-->
<string-array name="colorArray">
<item>Black - black text is not visible on a black background</item>
<item>Burgundy</item>
<item>Green</item>
<item>Blue</item>
<item>White - white text is not visible on a white background</item>
</string-array>
<string-array name="colorValues">
<item>#000000</item>
<item>#800020</item>
<item>#3C8D0D</item>
<item>#7068FF</item>
<item>#ffffff</item>
</string-array>
在活动中:
public class MainActivity extends AppCompatActivity { ...
TextView titleView, descriptionView;
titleView = (TextView) findViewById(R.id.titleView);
descriptionView = (TextView) findViewById(R.id.descriptionView);
//get text color and background color from shared preferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
color = prefs.getString("color", "1");
if(!(color == null)) {
titleView.setTextColor(Color.parseColor(color));
descriptionView.setTextColor(Color.parseColor(color));
} else {
titleView.setTextColor(BLACK);
descriptionView.setTextColor(BLACK);
}
以及 TextViews 的 xml:
<TextView
android:layout_width="wrap_content"
android:id= "@+id/titleView"
android:layout_height="wrap_content"
style="@style/CodeFont"
android:textColor="#000000"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id= "@+id/descriptionView"
style="@style/CodeFont"
android:layout_below="@+id/linkView"/>
我在第一次运行应用程序时将 else 设置为默认设置,共享首选项中没有保存任何内容。我不确定它是否有必要,但我在应用程序在我的手机上崩溃时添加了它,认为它崩溃的原因是没有存储的设置。
该应用程序安装在我的手机上并立即崩溃。我试图查看它的设置,但从来没有任何改变。我已经尝试卸载并重新安装该应用程序。同样,它不能在我的手机上运行,但它可以在模拟器上完美运行。
谁能提供一个建议来帮助我的应用在我的手机上运行?非常感谢。
【问题讨论】:
-
你能修复它吗?
标签: java android xml sharedpreferences