SFML community forums

Help => Window => Topic started by: jwurzer on December 04, 2017, 04:54:16 pm

Title: Android: java activity doesn't response/react (freeze) after closing native sfml
Post by: jwurzer on December 04, 2017, 04:54:16 pm
Hi sfml community and developers ;-)

Android java activity doesn't response/react (freeze) after closing native sfml activity.

I have two activities. One normal (java) activity and the native (sfml) activity.
The java activity is the main activity. I use this activity to open usb devices (like usb midi device)
and forward the open handle (per file descriptor) to the sfml application.

The native activity is started by a methode from the java activity like this:

   Intent intent=new Intent();
        intent.setComponent(new ComponentName("com.foo.myapp", "android.app.NativeActivity"));
        startActivity(intent);

Everything works great.
At the sfml event loop I set the window active and non-active if the events sf::Event::LostFocus
and sf::Event::GainedFocus happends. Therefore pressing the home button is no problem.
(Without setActive() problems exist. see: https://github.com/SFML/SFML/issues/755 https://pastebin.com/21sChJU6)

The problem begins when I close the native activity.
I close the native activity by closing the Sfml window (with close() member function) and return at the main sfml function.
After this the methode onResume() from the java activity is called (that's fine) but the java activity doesn't react on any touch or back-button.
The main java activity is shown but doesn't react. It looks like it is freezed.
Also if I call finish() at the onResume() methode (for exit the main java activity) only onPause() is called but no onDestroy().
My workaround is to call finish() at onResume() and call System.exit(0) at onPause() if the native activity was closed.
This Hack quits the java activity and clean the process.

What I am making wrong that the java activity is freezed after closing the native activity?

It would be really nice if I doesn't need the dirty exit(0) for closing the java activity.

I use the lastest master branch from SFML for android.

Here my manifest file.

My min sdk api version and my target sdk api version is both 15.

Manifest file:
--------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.foo.myapp">

    <uses-feature android:glEsVersion="0x00010001" />
    <uses-feature android:name="android.hardware.usb.host" />

    <uses-permission android:name="android.permission.USB_PERMISSION" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    <application
       android:allowBackup="true"
       android:icon="@mipmap/ic_launcher"
       android:label="@string/app_name"
       android:supportsRtl="true"
       android:theme="@style/AppTheme"
       >
        <activity android:name=".MyAppActivity" android:launchMode="singleTask"
           android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"
           >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
           android:name="android.app.NativeActivity"  android:launchMode="singleTask"
           android:configChanges="keyboardHidden|orientation|screenSize"
           android:icon="@mipmap/ic_launcher"
           android:label="@string/app_name"
           android:theme="@style/Theme.AppCompat.Light.NoActionBar.FullScreen"
           >
            <meta-data
               android:name="android.app.lib_name"
               android:value="myapp-sfml-activity" />
            <meta-data
               android:name="sfml.app.lib_name"
               android:value="myapp-main" />
        </activity>
    </application>

</manifest>
 

styles.xml:
-----------
<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <!-- extra style for fullscreen added -->
    <style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="@style/Theme.AppCompat.Light">
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>
</resources>