【问题标题】:The app works fine on AVD, but not on real device该应用程序在 AVD 上运行良好,但在真实设备上无法运行
【发布时间】:2014-08-29 10:45:14
【问题描述】:

我的项目确实有很大的问题。当我的手机通过 USB 数据线连接到计算机时,一切正常,但是当手机断开连接时,应用程序无法按预期工作。所以,我已经尝试过android.os.Debug.waitForDebugger(),我删除了所有@SuppressLint("NewApi"),我的手机上也激活了USB调试器,但我认为问题可能出在Manifest文件中。谁能告诉我,在这种情况下可以做什么?

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.androproject"
        android:versionCode="1"
        android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/fritz_logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        >
        <activity
            android:windowSoftInputMode="adjustPan"
            android:name="com.example.androproject.MainActivity"
            android:label="@string/app_name" 
            android:screenOrientation="portrait"
            android:theme="@style/ThemeWithCorners"
            android:configChanges="keyboardHidden|orientation">
    <intent-filter>
            <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>       
        <activity
            android:name="com.example.androproject.RegisterDnsAndUser" 
            android:screenOrientation="portrait"
            android:theme="@style/ThemeWithCorners"
            android:configChanges="keyboardHidden|orientation"/>               
        <activity
            android:name="com.example.androproject.MenuApp" 
            android:screenOrientation="portrait"
            android:theme="@style/ThemeWithCorners"            
            android:configChanges="keyboardHidden|orientation"/>               
    </application>
</manifest>

我正在使用以下处理程序代码。当我输入 40000 毫秒时,应用程序可以工作,但是当我输入 60000 毫秒时,如果电缆断开,我的应用程序将无法工作。

 handler.postDelayed(myRunnable = new Runnable(){
                @Override
                public void run() {                         
                    if(btnToggle.isChecked()){   
                        btnToggle.setChecked(false);
                        btnToggleTimer.setChecked(false);                   
                    }else{
                        btnToggle.setChecked(true);
                        btnToggleTimer.setChecked(false);
                    }    
                }                 
              }, min*60000);

【问题讨论】:

  • 您能否提供有关“应用程序无法按预期运行”的更多详细信息?你到底看到了什么不同?
  • avd 和 device 的 api 级别是否相同?我们需要更多细节!
  • 是的,我已经编辑了更多细节,是的,它们是相同的 api 级别。

标签: java android


【解决方案1】:

您很可能在设置菜单的开发人员选项中启用了“保持清醒”模式。当您断开手机与充电器的连接时,它会在几秒钟后进入睡眠模式。

解决方案是通过PowerManager 使用部分唤醒锁,或者(在上述情况下)使用 PendingIntent 和AlarmManager 稍后触发事件。

【讨论】:

  • 是一样的。 40000 毫秒可以正常工作,但如果我设置 1 分钟就不行了。
猜你喜欢
  • 2017-10-28
  • 2015-07-26
  • 1970-01-01
  • 2013-08-18
  • 1970-01-01
  • 1970-01-01
  • 2019-11-17
  • 1970-01-01
相关资源
最近更新 更多