英文:
Android App Not Open black screen problem
问题
我几天前制作了一个简单的Android WebView应用,它运行得很好,但问题是现在出现了,一段时间后应用无法打开,屏幕变黑,重新安装后就正常了,一段时间后又出现了相同的问题,如果有人帮助,将会非常友善。
>小米红米Note 6 Pro
Android 版本 9 PIE
# 源代码 #
### manifest.xml ###
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".web_main">
</activity>
<activity
android:name=".setting">
</activity>
<activity
android:name=".about"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
<activity
android:name=".update">
</activity>
<activity
android:name=".download">
</activity>
<activity android:name=".play_ui"
android:theme="@style/Theme.AppCompat.Light">
</activity>
</application>
```
### build.gradle ###
```
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.musicwala.djaman"
minSdkVersion 14
targetSdkVersion 29
versionCode 3
versionName "3.1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile ('android.arch.core:runtime:+') {
force = true
}
compile 'com.android.support:appcompat-v7:27.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
### MainActivity.java ###
package com.musicwala.djaman;
import android.app.;
import android.os.;
import android.view.Window;
import android.widget.AbsoluteLayout.LayoutParams;
import android.view.WindowManager;
import android.content.Intent;
import android.util.Log;
import android.net.NetworkInfo;
import android.net.ConnectivityManager;
import android.content.Context;
import android.content.DialogInterface;
import android.provider.Settings;
import android.widget.Toast;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
if(isNetworkConnectionAvailable() == true)
{
final Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 1s
Intent intent = new Intent(MainActivity.this,web_main.class);
startActivity(intent);
finish();
}
}, 1000);
}
}
public void checkNetworkConnection(){
AlertDialog.Builder builder =new AlertDialog.Builder(MainActivity.this);
builder.setTitle("No internet Connection");
builder.setMessage("Please turn on internet connection to continue!");
builder.setPositiveButton("Turn On", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MainActivity.this.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
}).show();
builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finishAffinity();
}
}).show();
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
public boolean isNetworkConnectionAvailable(){
ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnected();
if(isConnected) {
Log.d("Network", "Connected");
return true;
}
else{
checkNetworkConnection();
Log.d("Network","Not Connected");
return false;
}
}
}
### 在我的其他设备上也能正常运行 ###
> Android v8.0 Oreo
英文:
I made a simple app of android webview a few days ago and it runs fine but the problem is happening now that after some time the app is not open, that screen is going black and reinstall After doing it, it is going right, for some time it is going right, then the same problem is coming, if someone helps, it will be very kind.
>Mi redmi note 6 Pro
Android V 9 PIE
Source Code
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.musicwala.djaman" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:usesCleartextTraffic="true"
android:icon="@drawable/main"
android:label="@string/app_name"
android:theme="@style/AppTheme"
android:resizeableActivity="true">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".web_main">
</activity>
<activity
android:name=".setting">
</activity>
<activity
android:name=".about"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
</activity>
<activity
android:name=".update">
</activity>
<activity
android:name=".download">
</activity>
<activity android:name=".play_ui"
android:theme="@style/Theme.AppCompat.Light">
</activity>
</application>
</manifest>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.musicwala.djaman"
minSdkVersion 14
targetSdkVersion 29
versionCode 3
versionName "3.1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile ('android.arch.core:runtime:+') {
force = true
}
compile 'com.android.support:appcompat-v7:27.+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
MainActivity.java
package com.musicwala.djaman;
import android.app.*;
import android.os.*;
import android.view.Window;
import android.widget.AbsoluteLayout.LayoutParams;
import android.view.WindowManager;
import android.content.Intent;
import android.util.Log;
import android.net.NetworkInfo;
import android.net.ConnectivityManager;
import android.content.Context;
import android.content.DialogInterface;
import android.provider.Settings;
import android.widget.Toast;
public class MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//requestWindowFeature(Window.FEATURE_NO_TITLE);
// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
if(isNetworkConnectionAvailable() == true)
{
final Handler h = new Handler();
h.postDelayed(new Runnable() {
@Override
public void run() {
//Do something after 1s
Intent intent = new Intent(MainActivity.this,web_main.class);
startActivity(intent);
finish();
}
}, 1000);
}
}
public void checkNetworkConnection(){
AlertDialog.Builder builder =new AlertDialog.Builder(MainActivity.this);
builder.setTitle("No internet Connection");
builder.setMessage("Please turn on internet connection to continue!");
builder.setPositiveButton("Turn On", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
MainActivity.this.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
}
}).show();
builder.setNegativeButton("Exit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finishAffinity();
}
}).show();
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
public boolean isNetworkConnectionAvailable(){
ConnectivityManager cm =
(ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null &&
activeNetwork.isConnected();
if(isConnected) {
Log.d("Network", "Connected");
return true;
}
else{
checkNetworkConnection();
Log.d("Network","Not Connected");
return false;
}
}
}
And is working fine in my other device
>Android v8.0 Oreo
答案1
得分: 1
清除手机缓存,数据,并重新启动手机!
英文:
Clear your phone cache ,data and restart your phone!
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论