Hi i have weird problem. My app works fine on the PC. On the Android this also works fine but only until i don’t use button to exit game. When i click this button and i want open my app again, this has been crashed without any error. Only "(Appname) has been stopped. I’m use
native.requestExit()
function for exit game. If i close app with umm… “app manager?” this working still fine… But not saves my stats. So this problem maybe caused by native.requestExit or by my code to save stats. But this on PC working fine and don’t give any errors and warnings (Sorry for my eng)
Code for save my stats:
local composer = require 'composer'; display.setStatusBar(display.HiddenStatusBar); local audioManager = require 'sounds'; local userd = require 'userdata'; local function convertToBoolean(data) return data == '1'; end local function onSystemEvent( event ) if (event.type == 'applicationExit') then local soundOp,musicOp = audioManager.get(); local userData = userd.get(); local appPreferences = { soundsBool = soundOp, musicBool = musicOp, answers = userData.answers, goodAnswers = userData.goodAnswers, badAnswers = userData.badAnswers, allRounds = userData.allRounds, winningRounds = userData.winningRounds, points = userData.points }; system.setPreferences('app', appPreferences); elseif (event.type == 'applicationStart') then local allA, goodA, badA, rounds, winRounds, points, soundOp, musicOp = system.getPreference('app', 'answers', 'number'), system.getPreference('app', 'goodAnswers', 'number'), system.getPreference('app', 'badAnswers', 'number'), system.getPreference('app', 'allRounds', 'number'), system.getPreference('app', 'winningRounds', 'number'), system.getPreference('app', 'points', 'number'),system.getPreference('app', 'soundsBool', 'string'), system.getPreference('app', 'musicBool', 'string'); if (type(allA) == 'nil') then -- others var are the same allA, goodA, badA, rounds, winRounds, points,soundOp,musicOp = 0, 0, 0, 0, 0, 0, '1', '1'; end setUserData({ answers = allA, goodAnswers = goodA, badAnswers = badA, allRounds = rounds, winningRounds = winRounds, points = points, }); local soundOp, musicOp = convertToBoolean(soundOp), convertToBoolean(musicOp); updateSoundsData(soundOp, musicOp); composer.gotoScene('menu'); end end Runtime:addEventListener( "system", onSystemEvent );
userdata and soundsManager are table/returns table. Imo this weird problem because this works on pc without any errors, but on android crashes.