BackHandler.exitApp() is not closing the services of react-native android app - android

When I am using BackHandler.exitApp() to close the app and not removing the app from task manager window of the android, when I am again opening the app, it seems before it starts the service init, it start to call service functions.
So as a result, I am doing init of this.db = new Datastore({ filename: dbPath, autoload: true, ...options }); , But before it happens the database service is already trying to use this.db, so, as a result, it is saying this.db as undefined.
Can anyone tell me how can I do the init first and then start the services everytime I open the app? Or how can I exit a react native app with completely kill all the tasks?

I solved this by this module react-native-exit-app - https://www.npmjs.com/package/react-native-exit-app
It closes the app completely.
But it would be great if someone can explain the question.

Related

How can I write a test to wait for close app using Flutter Driver

I have to test my agreement when the app is first launched: if the user do not agree, than the app must close.
Most of the test are already working but I couldn't figure out how to test if the app has closed.
Is there any way to test this behavior and "expect for close app"?
Thanks,
Ian
Run the app
Initialise flutter driver.
Check that flutter driver is not null
Close the app (the app should be closed and not backgrounded)
driver.checkHealth
When you trigger app exit you may verify if the app was exited by its exit code
expect(exitCode, 0);
I am using this approach in my tests and it works great.
usage in a sample test:
https://github.com/maheshmnj/navbar_router/blob/885c68ae974250167df3c1dccee3e6474f5ddd39/test/navbar_router_test.dart#L210

getServerAuthCode always return null after you kill the android app in background

I found out that the Play-Game-Services Integration with GetServerAuthCode Integration does have an error when the following situation:
After I finish the integration and i call getServerAuthCode, it
bring me the AuthCode value.
After I close the app in the background and i re-open the app, the silentSignIn always fail.
Now I can't retrieve my AuthCode unless I re-signIn the app, this cause an issue as player need to always re-signIn the app when starting of the app. It doesn't bring a good User Experience.
I wish to know that is there something that i miss out during the integration? Or it is an intended feature? If it is an intended feature, is there any solution/work-around that can help me solve my issue?

Close Android App programatically in Xamarin Forms project

I am using the following code to close the android app in a Xamarin Form project.
var activity = (Activity)Forms.Context;
activity.FinishAndRemoveTask();
It is closing the app but if again I tap on the app it is not opening the new instance of the app as the I can see debugger is still active .
Can anyone help ?
it is not opening the new instance of the app as the I can see debugger is still active
When you use activity.FinishAndRemoveTask() method, this method cant kill your Android app, it just means :
Finishes all activities in this task and removes it from the recent tasks list.
You could use the following code to implement this feature :
FinishAndRemoveTask();
Java.Lang.JavaSystem.Exit(0);// Terminate JVM

Regarding the android app crash

Actually my android app is using quickblox backend, If app got crash somewhere then session gets destroyed but app is not getting closed. it just goes to previous activity, but user is not able to do any operation to backend means service call(saying token required).
So I want a solution that will close my application so that user again restarted the app then session will be regained or we can start the splash activity.
please give me a solution .
I will be grateful , thanks
There is an option to get the app crash data using UncaughtExceptionHandler in your application class.
So , using this you will be notified when your app will crash. but if you want to exit your app , this is not a good solution as suggested by google core team. So you should handle this using try catch and in catch again calling the service to get the token.
First it is not a good use case. Instead of that you can try to catch exception and try to recall your service at runtime.

PushNotifications and MVVMCross

I have a service which handles my push notification. When the app is running, everything is fine, but once the app is not running I am getting a null reference exception. I have traced it back to the following line :
newIntent = Mvx.Resolve<IMvxAndroidViewModelRequestTranslator> ().GetIntentFor (request);
This line is used to get the intent for the status bar notification so when the user clicked on it it will take him to the appropriate page inside the app. I am pretty sure that This is null because the application is not running and the MvvmCross framework did not have a chance to initialize and register the IMvxAndroidViewModelRequestTranslator.
My question is what should I use as an alternative?
UPDATE
So I dis some reading and I believe that a regular intent wont work and break my app. I was thinking about creating a dummy activity In my app which will get the regular intent I will send and move on to use the IMvxAndroidViewModelRequestTranslator (which should be not null since the app was started) and create an MvvmCross navigation request.
Any thoughts?
UPDATE 2
Tried the approach above with no luck... still failing on the same line...
So basically the question is how can I launch the app from the status bar while making the MvvmCross eco system start as well...
Thanks
Amit
So what I ended up doing is once the notification arrived and the Mvx.Resolve threw an exception I (meaning the app is not running), I saved the notification data to the app preferences and launched the app to its main activity and there I simpley checked for the notification data and if it existed I navigated to the appropriate activity.
When the Android UI starts, then MvvmCross runs Setup to initialise things like IoC, your application, etc
If you need to initialise your MvvmCross application within a non-UI setting, then try the answer from MvvmCross DataService in an Android Broadcast listener which shows how to access the same setup that the UI uses.

Categories

Resources