该应用在AVD上运行良好,但在真实设备上运行不正常
我的项目真的有很大的问题。当我的手机通过USB线连接到电脑时,一切正常,但手机断开连接时,应用程序无法正常工作。所以,我已经试过android.os.Debug.waitForDebugger()
,我删除了全部@SuppressLint("NewApi")
,我的手机上也启动了USB调试器,但我认为问题可能出现在Manifest文件中。有人可以告诉我,在这种情况下可以做些什么?该应用在AVD上运行良好,但在真实设备上运行不正常
<?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);
很可能您已在设置菜单的开发人员选项中启用了“保持清醒”模式。当您将手机与充电器断开连接后,它会在几秒钟后进入睡眠模式。
解决方法是使用PowerManager或(在上例中)使用部分唤醒锁定使用PendingIntent和AlarmManager稍后触发事件。
这是一样的。对于40000毫秒工作正常,但如果我设置1分钟它不。 – Soyer 2014-08-29 15:50:19
你的想法不起作用 – 2017-04-18 13:31:50
你能提供更多关于“应用程序无法正常工作”的详细信息吗?你看到什么不同? – Marius 2014-08-29 10:46:46
是AVD和设备相同的API级别?我们需要更多的细节! – 2014-08-29 10:48:30
是的,我已经编辑了更多的细节,是的,他们是相同的API级别。 – Soyer 2014-08-29 10:53:25