Android应用程序无法打开的黑屏问题

huangapple go评论75阅读模式
英文:

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

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;manifest xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    package=&quot;com.musicwala.djaman&quot; &gt;
    &lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
    &lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot;/&gt;
    &lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;
    &lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot;/&gt;
    &lt;application
        android:allowBackup=&quot;true&quot;
        android:usesCleartextTraffic=&quot;true&quot;
        android:icon=&quot;@drawable/main&quot;
        android:label=&quot;@string/app_name&quot;
        android:theme=&quot;@style/AppTheme&quot;
        android:resizeableActivity=&quot;true&quot;&gt;
        &lt;activity

            android:name=&quot;.MainActivity&quot;
            android:label=&quot;@string/app_name&quot; 
            android:theme=&quot;@android:style/Theme.NoTitleBar.Fullscreen&quot;&gt;

            &lt;intent-filter&gt;
                &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;

                &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
        &lt;activity
            android:name=&quot;.web_main&quot;&gt;
        &lt;/activity&gt;
        &lt;activity
            android:name=&quot;.setting&quot;&gt;
        &lt;/activity&gt;
        &lt;activity
            android:name=&quot;.about&quot;
            android:theme=&quot;@android:style/Theme.NoTitleBar.Fullscreen&quot;&gt;
        &lt;/activity&gt;
        &lt;activity
            android:name=&quot;.update&quot;&gt;

        &lt;/activity&gt;
        &lt;activity
            android:name=&quot;.download&quot;&gt;

        &lt;/activity&gt;
        &lt;activity android:name=&quot;.play_ui&quot;
            android:theme=&quot;@style/Theme.AppCompat.Light&quot;&gt;

        &lt;/activity&gt;
    &lt;/application&gt;

&lt;/manifest&gt;

build.gradle

apply plugin: &#39;com.android.application&#39;

android {
    compileSdkVersion 29

    defaultConfig {
        applicationId &quot;com.musicwala.djaman&quot;
        minSdkVersion 14
        targetSdkVersion 29
        versionCode 3
        versionName &quot;3.1.0&quot;
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile(&#39;proguard-android.txt&#39;), &#39;proguard-rules.pro&#39;
        }
    }
}

dependencies {
    compile (&#39;android.arch.core:runtime:+&#39;) {
       force = true
}   

    compile &#39;com.android.support:appcompat-v7:27.+&#39;
    compile fileTree(dir: &#39;libs&#39;, include: [&#39;*.jar&#39;])
}

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(&quot;No internet Connection&quot;);
        builder.setMessage(&quot;Please turn on internet connection to continue!&quot;);
        builder.setPositiveButton(&quot;Turn On&quot;, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    MainActivity.this.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                }
            }).show();

        builder.setNegativeButton(&quot;Exit&quot;, 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 &amp;&amp;
            activeNetwork.isConnected();
        if(isConnected) {
            Log.d(&quot;Network&quot;, &quot;Connected&quot;);
            return true;
        }
        else{
            checkNetworkConnection();
            Log.d(&quot;Network&quot;,&quot;Not Connected&quot;);
            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!

huangapple
  • 本文由 发表于 2020年5月29日 16:06:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/62081395.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定