简体   繁体   English

运行后,Android应用程序显示黑屏

[英]Android application displays black screen after running

When I click "Run as an Android Application" on Eclipse, the following is displayed in the console 当我在Eclipse上单击“以Android应用程序运行”时,控制台中将显示以下内容

[2014-06-05 20:07:18 - StudentConnect] Android Launch!
[2014-06-05 20:07:18 - StudentConnect] adb is running normally.
[2014-06-05 20:07:18 - StudentConnect] Performing sandhu.student.connect.SplashActivity activity launch
[2014-06-05 20:07:18 - StudentConnect] Using default Build Tools revision 19.0.0
[2014-06-05 20:07:18 - StudentConnect] Refreshing resource folders.
[2014-06-05 20:07:18 - StudentConnect] Using default Build Tools revision 19.0.0
[2014-06-05 20:07:18 - StudentConnect] Starting incremental Pre Compiler: Checking resource changes.
[2014-06-05 20:07:18 - StudentConnect] Nothing to pre compile!
[2014-06-05 20:07:18 - StudentConnect] Starting incremental Package build: Checking resource changes.
[2014-06-05 20:07:18 - StudentConnect] Using default Build Tools revision 19.0.0
[2014-06-05 20:07:18 - StudentConnect] Skipping over Post Compiler.
[2014-06-05 20:07:20 - StudentConnect] Application already deployed. No need to reinstall.
[2014-06-05 20:07:20 - StudentConnect] Starting activity sandhu.student.connect.SplashActivity on device 0f0898b2
[2014-06-05 20:07:21 - StudentConnect] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=sandhu.student.connect/.SplashActivity }
[2014-06-05 20:07:21 - StudentConnect] ActivityManager: Warning: Activity not started, its current task has been brought to the front

After deployed to my phone, it only displays a black screen. 部署到我的手机后,它仅显示黑屏。 I recently implemented a splash screen, but it was working fine before; 我最近实现了启动屏幕,但之前运行良好。 however I think it might have something to do with the problem. 但是我认为这可能与问题有关。 Here are my java and xml files: 这是我的Java和xml文件:

MainActivity.java MainActivity.java

package sandhu.student.connect;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

    public WebView student_zangle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);  
        WebView student_zangle = (WebView) findViewById(R.id.student_zangle);
        student_zangle.loadUrl("https://zangleweb01.clovisusd.k12.ca.us/studentconnect/");
        student_zangle.setWebViewClient(new WebViewClient());
        student_zangle.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
        WebSettings settings = student_zangle.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setBuiltInZoomControls(true);      
        settings.setLoadWithOverviewMode(true);
        settings.setUseWideViewPort(true);
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        WebView student_zangle = (WebView) findViewById(R.id.student_zangle);
        if ((keyCode == KeyEvent.KEYCODE_BACK) && student_zangle.canGoBack()) {
            student_zangle.goBack();
            return true;
        }
        else
        {
            finish();
        }
        return super.onKeyDown(keyCode, event);
    }

}

activity_main.xml activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/blue"
    tools:context=".MainActivity" >

    <WebView
        android:id="@+id/student_zangle"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</RelativeLayout>

SplashActivity.java SplashActivity.java

package sandhu.student.connect;


import android.os.Bundle;
import android.preference.PreferenceActivity;

public class SplashActivity extends PreferenceActivity {

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        addPreferencesFromResource(R.xml.prefs);
    }



 }

splash_activity.xml splash_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/blue"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="250dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="145dp"
        android:contentDescription="@string/zangle_logo"
        android:src="@drawable/logo" />

</RelativeLayout>

Also, here is a full copy of the logcat error output: 另外,这是logcat错误输出的完整副本:

06-05 20:19:46.698: E/Watchdog(817): !@Sync 1952
06-05 20:20:09.971: E/memtrack(16438): Couldn't load memtrack module (No such file or directory)
06-05 20:20:09.971: E/android.os.Debug(16438): failed to load memtrack module: -2
06-05 20:20:11.012: E/memtrack(16451): Couldn't load memtrack module (No such file or directory)
06-05 20:20:11.012: E/android.os.Debug(16451): failed to load memtrack module: -2
06-05 20:20:11.202: E/EnterpriseContainerManager(817): ContainerPolicy Service is not yet ready!!!

Please help me figure out what is wrong, or at least point me in the right direction. 请帮助我找出问题所在,或者至少指出正确的方向。 Thanks in advance. 提前致谢。

This message :"ActivityManager: Warning: Activity not started, its current task has been brought to the front" means adb is detecting that the same app is already deployed, so it just bring the app in front. 此消息:“ ActivityManager:警告:活动尚未开始,其当前任务已移到最前面”,意味着adb正在检测到已经部署了同一应用程序,因此它只是将该应用程序放在最前面。 You can try to remove it from your phone or launch it in debug it you want the app to be redeployed. 您可以尝试从手机中将其删除,也可以在调试时启动它,以重新部署该应用。

Try to clean project if you are that the app is not up to date on the phone. 如果您认为该应用不是最新的手机,请尝试清理项目。

It is not an error message, it is a warning. 这不是错误消息,而是警告。 What the system is trying to tell you: The application on the device is the same as your application in Eclipse. 系统试图告诉您的内容:设备上的应用程序与Eclipse中的应用程序相同。 And because the application is already running on the device (recompilation will not be done if you have not changed the code , it doesn't go through the uninstall-install process), the system tells you that it is not going to kill and restart it, but bring the activity of your already running app into the foreground. 并且由于该应用程序已经在设备上运行(如果您没有更改代码,则不会重新编译,它不会经过卸载-安装过程),因此系统会告诉您它不会终止并重新启动它,但是将已经运行的应用程序的活动置于前台。 This is pretty normal. 这很正常。

The warning will not continue if you edit your code and run it (because the app is then killed, reinstalled and started). 如果您编辑代码并运行它,警告将不会继续(因为该应用程序随后被终止,重新安装并启动)。

I do get this warning many times, I use a lame technique. 我确实多次收到此警告,我使用了一种me脚的技术。 Add a space anywhere in your code (in any file). 在代码中的任何位置(任何文件中)添加一个空格。 Just Save the project and run. 只需保存项目并运行。 It will then go through the uploading and installing process again. 然后它将再次经历上载和安装过程。 This is the easiest way to go about it without actually changing any code that matters. 这是最简单的方法,无需实际更改任何重要的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM