發表文章

目前顯示的是 6月, 2016的文章

使用Stetho觀察App裡的SharedPreferences與Sqlite資料

圖片
當我們想在手機裡暫存一些資料,方便紀錄使用者在App的設定紀錄時,Android官方提供SharedPreferces的方法(存成XML檔案),或是要以資料庫(可以新增/刪除/修改)的方式儲存更多的資料時,Android也提供了Sqlite的方法(存成db檔案)。 但是如果開發者在debug的過程想要查看所存放的資料內容,比較常見的方法是使用adb shell透過下指令的方式,但是這個方式不是很方便也比較不直覺,於是可以使用Facebook所提供第三方的Library讓我們更方便查看資料內容。 使用這個Library的方法非常的簡單,只要依照下列的幾個步驟即可達成: 1.在Gradle加入dependencies dependencies { compile 'com.facebook.stetho:stetho:1.3.1' } 2.建立Appliction class public class MyApplication extends Application { @Override public void onCreate() { super.onCreate(); Stetho.initializeWithDefaults(this); } } 3.設定AndroidManifest.xml < android:name=".MyApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action and