Skip to content

Commit

Permalink
Android: Save settings in onStop
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Jan 22, 2024
1 parent 2b9c27d commit 0990c55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions android/app/src/main/java/net/minetest/minetest/GameActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ protected void onResume() {
makeFullScreen();
}

private native void saveSettings();

@Override
protected void onStop() {
super.onStop();
// Avoid losing setting changes in case the app is onDestroy()ed later.
// Saving stuff in onStop() is recommended in the Android activity
// lifecycle documentation.
saveSettings();
}

@Override
public void onBackPressed() {
// Ignore the back press so Minetest can handle it
Expand Down
7 changes: 7 additions & 0 deletions src/porting_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "config.h"
#include "filesys.h"
#include "log.h"
#include "settings.h"

#include <sstream>
#include <exception>
Expand All @@ -39,6 +40,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,

extern int main(int argc, char *argv[]);

extern "C" JNIEXPORT void JNICALL
Java_net_minetest_minetest_GameActivity_saveSettings(JNIEnv* env, jobject /* this */) {
if (!g_settings_path.empty())
g_settings->updateConfigFile(g_settings_path.c_str());
}

namespace porting {
// used here:
void cleanupAndroid();
Expand Down

0 comments on commit 0990c55

Please sign in to comment.