1、在虚拟机上我使用的是Android5.0版本,当前manifests的application标签配置如下,正确运行没问题。
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="qsj_weather_task_6"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.example.qsj_weather_task_6.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
2、但是放到真机上(Android 9)就会闪退,于是在application标签里面添加一行代码:android:usesCleartextTraffic=“true”。就可以正确运行了。
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="qsj_weather_task_6"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/AppTheme">
<activity android:name="com.example.qsj_weather_task_6.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>