简体   繁体   English

我的应用程式停止在AVD中运作

[英]My app stops working in the AVD

I'm very new. 我很新。 I don't have any error warning, but when I test, it unfortunately stops working. 我没有任何错误警告,但不幸的是,当我测试时,它停止工作。 I've changed the AVD ram value, but still not work. 我已经更改了AVD内存值,但仍然无法正常工作。 I tried to export it to my phone, but it fails to install. 我试图将其导出到手机中,但无法安装。

my activity file 我的活动档案

package com.abdo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

 private static String logtag = "TwoButtonApp";//for use as the tag when logging 

 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button buttonStart = (Button)findViewById(R.id.buttonStart);        
     buttonStart.setOnClickListener(startListener); // Register the onClick listener with the implementation above

     Button buttonStop = (Button)findViewById(R.id.buttonStop);        
     buttonStop.setOnClickListener(stopListener); // Register the onClick listener with the implementation above
    }

    //Create an anonymous implementation of OnClickListener
    private OnClickListener startListener = new OnClickListener() {
        public void onClick(View v) {
          Log.d(logtag,"onClick() called - start button");   
          Intent a = new Intent(MainActivity.this, ManuActivity.class);
          startActivity(a);

          Log.d(logtag,"onClick() ended - start button");
        }
    };

    // Create an anonymous implementation of OnClickListener
    private OnClickListener stopListener = new OnClickListener() {
        public void onClick(View v) {
         Log.d(logtag,"onClick() called - stop button"); 
         Toast.makeText(MainActivity.this, "The Stop button was clicked.", Toast.LENGTH_LONG).show();
          Log.d(logtag,"onClick() ended - stop button");
        } 
    };


    @Override
 protected void onStart() {//activity is started and visible to the user
  Log.d(logtag,"onStart() called");
  super.onStart();  
 }
 @Override
 protected void onResume() {//activity was resumed and is visible again
  Log.d(logtag,"onResume() called");
  super.onResume();

 }
 @Override
 protected void onPause() { //device goes to sleep or another activity appears
  Log.d(logtag,"onPause() called");//another activity is currently running (or user has pressed Home)
  super.onPause();

 }
 @Override
 protected void onStop() { //the activity is not visible anymore
  Log.d(logtag,"onStop() called");
  super.onStop();

 }
 @Override
 protected void onDestroy() {//android has killed this activity
   Log.d(logtag,"onDestroy() called");
   super.onDestroy();
 }
}

manifest 表现

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.abdo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/FullscreenTheme" >
        <activity
            android:name="com.abdo.MainActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.abdo.ManuActivity"
            android:label="@string/title_activity_manu" >
        </activity>
    </application>

</manifest>
  • Firstly set the android:debuggable to true in your manifest file. 首先在清单文件中将android:debuggable设置为true。
  • Secondly, turn on install apk from unknown sources in your android device's settings and also turn on allow to debug through usb setting in developer settings or kinda that (don't know how this calls on english, I have russian interface). 其次,在您的android设备的设置中打开install apk from unknown sources ,然后在developer settings或某种程度上打开allow to debug through usb设置allow to debug through usb (不知道这在英语中怎么称呼,我有俄语界面)。
  • Then run your code in debug mode, pressing debug button in your IDE. 然后在调试模式下运行代码,在IDE中按debug按钮。

And also try to write your code after the super function call. 并在super函数调用after尝试编写代码。

 @Override
 protected void onStart() {//activity is started and visible to the user
  super.onStart();  
  Log.d(logtag,"onStart() called");
 }

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

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