Skip to content

Commit

Permalink
Android: Reload native libraries from all Game Browser / Setting acti…
Browse files Browse the repository at this point in the history
…vities

Otherwise gives UnsatisfiedLinkError when the app was killed due to OOM etc.
  • Loading branch information
Ghabry committed Jan 22, 2025
1 parent e07493f commit 3f1fae8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
package org.easyrpg.player;

import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import org.easyrpg.player.settings.SettingsManager;

public class BaseActivity extends AppCompatActivity {
/**
* This activity is used by the GameBrowser and the settings.
*/
public class BaseActivity extends AppCompatActivity {
public static Boolean libraryLoaded = false;

private static void loadNativeLibraries() {
if (!libraryLoaded) {
try {
System.loadLibrary("easyrpg_android");
System.loadLibrary("gamebrowser");
libraryLoaded = true;
} catch (UnsatisfiedLinkError e) {
Log.e("EasyRPG Player", "Couldn't load libgamebrowser: " + e.getMessage());
throw e;
}
}
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Retrieve User's preferences
SettingsManager.init(getApplicationContext());
init();
}

@Override
protected void onResume() {
super.onResume();

init();
}

protected void init() {
// Retrieve User's preferences
SettingsManager.init(getApplicationContext());

loadNativeLibraries();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@

public class GameBrowserActivity extends BaseActivity
implements NavigationView.OnNavigationItemSelectedListener {
public static Boolean libraryLoaded = false;

private static final int THUMBNAIL_HORIZONTAL_SIZE_DPI = 290;
private static Game selectedGame;

Expand All @@ -58,17 +56,6 @@ public class GameBrowserActivity extends BaseActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (!libraryLoaded) {
try {
System.loadLibrary("easyrpg_android");
System.loadLibrary("gamebrowser");
libraryLoaded = true;
} catch (UnsatisfiedLinkError e) {
Log.e("EasyRPG Player", "Couldn't load libgamebrowser: " + e.getMessage());
throw e;
}
}

SDL.setContext(getApplicationContext());

setContentView(R.layout.activity_games_browser);
Expand Down

0 comments on commit 3f1fae8

Please sign in to comment.