androidmaximizegoogle-chrome-osapplication-restart

Android app on Chrome OS restarts each time is pressed "Maximize" button


Google play runs now in Beta on some Chromebooks. I have application on google play and after downloading it to Chromebook I experienced this issue : Application's Activity is restarted Each time is pressed "Maximize" button. Of course, I want keep my application compatible with Chrome OS. I am not sure where is the problem, on android device it works well.

This problem can be well reproduce with simple hello world project made with Android studio (I use version 1.5) :

In Android studio press "Start a new Android Studio project", fill name and press next. I set compatibility for API 8+ and then I pick Empty activity. Project is set with min Sdk 8 and target sdk 23. To onCreate I added simple Toast message :

Toast.makeText(this, "Recreated", Toast.LENGTH_SHORT).show();

Resulted apk can be tested on Chrome OS. Each time is pressed "Maximize" button I see "Recreated" message.

I did nothing to AndroidManifest.xml. But I tested flags :

        android:configChanges="orientation|keyboardHidden"
        android:windowSoftInputMode="adjustResize"

without success.

Here is how looks my Activity code :

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toast.makeText(this, "Recreated", Toast.LENGTH_SHORT).show();
}

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);
    Toast.makeText(this, "onConfigurationChanged", Toast.LENGTH_SHORT).show();
} }

I expected that onConfigurationChanged event will be triggered each time I press "Maximize" button, but instead was called onCreate().

Please what I must do to prevent the Activity being restarted each time is "Maximize" button pressed. And how to handle that "resize" event.


Solution

  • Using android:configChanges="orientation|keyboardHidden|screenLayout|screenSize|smallest‌​ScreenSize" for the Activity in manifest should help.

    But, unfortunately, killing activity on configuration changes is recommended.