Soyer
Soyer

Reputation: 57

The app works fine on AVD, but not on real device

I really have very big problem with my project. When my phone is connected to the computer via USB cable, everything works fine, but when the phone is disconnected the app doesn't work as I expected. So, I have already tried with android.os.Debug.waitForDebugger(), I removed the all @SuppressLint("NewApi"), also USB debugger is activated on my phone, but I think the problem can be in the Manifest file. Can someone tell me, what can be done in this case?

<?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>

I am using the following, handler code. When I put 40000 ms, the app works, but when I put 60000 ms, my application doesn't work if the cable is disconnected.

 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);

Upvotes: 0

Views: 483

Answers (1)

mach
mach

Reputation: 8395

Most likely you have enabled the "Stay awake"-mode in the Developer options in the settings menu. When you disconnect the phone from the charger it will go into sleep mode after a few seconds.

The solution is to either use a partial wake-lock using the PowerManager or (in the above case) use a PendingIntent and the AlarmManager to trigger a event at a later time.

Upvotes: 1

Related Questions