有时候我们需要一些设置全局变量的配置,而且能在任何时候都可以调用,当然android也配置了SharedPreFerences数据持久化接口,非常适应配置信息的保存,因此可以创建一个继承Application的类——Config类,并在Mainifest.xml中的Application标签入口处配置:
具体配置如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<application
android:allowBackup="true"
android:name=".game2048.Config"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:requestLegacyExternalStorage="true"
android:theme="@style/Theme.MyApplication">
<activity
android:nam