How to make your app save automaticly? - java

I am working on an App in android studio. The only thing is that if you close the app you need to start over with the game. Do you guys know how i can integrate a autosave option in my app that every time the user closes the app and start it up again that they don't need to start over?

onSavedInstanceState is used when recreating an activity due to things like orientation changes. check this link: http://developer.android.com/training/basics/activity-lifecycle/recreating.html
If the user is exiting the application completely then you should look into persisting the data with a sqlite db or using shared preferences during the activity lifecycle, check this link: http://www.herongyang.com/Android/Android-Application-Activity-Lifecycle.jpg
When the user starts the app again then check the persisted data during onCreate()

Related

Android. make a system app that run another app

im making a app that observes for some apps that are runing or not and execute it if dont
i dont know how to oberserve other apps processes and how to start another app that wasnt maked by me.
all that i got for now is run it as system service.
another possibility is create a self app that restart it own when it crashes or be closed.
there is any way to do it ?
My cell is not rooted
For your question, you can learn the application sandbox.
https://source.android.com/security/app-sandbox
When the developer makes an application, they can define their intent filter and tt is some way to let another application invoke it.
You can uncompress .apk from another application and find out the file AndroidManifest.xml. And then you can try it.
But you can just control the part of door they open to you.

Java - android - change activity of app while running in the background

I'm developing an Android app with several types of alarms and triggers.
One of these alarms trigger if you stop moving (GPS tracking) while it's active.
Now, when the app runs in the background when this triggers the client doesn't update when you switch back in, and the only notification received is a push-notification from the backend service. If I enter through the notification, the client loads the alarm correctly.
The code base is quite extensive, and due to time and resources it would be best to avoid huge refactoring tasks.
Is there an easy way to make the app go from Activity A to Activity B when it's running in the background?
You cannot change the current Activity in the background without bringing the app to the foreground (using startActivity()). However, you can surely tell the app that when it is brought to the foreground it should start a certain Activity or rearrange the back stack or whatever.
Post some of the code and maybe we can help more.

On destroy does not get call when app closes from recents - Android

I am trying to create a mock location app. After the user chose a location, the app should spoof his location to the place he chose.
I want that when the user closes the app, from recent apps or by pressing the back button the app will stop to mock location.
After reading the docs and some debugging, I understand that the OnDestroy function does not get called when the user stop the app from recent apps.
How can I know when the user decided to kill the app?
Yes, there is no guarantee that onDestroy method will be called everytime.onDestroy is called when Android goes short of resources and it need to clean up to recover some memory resources.
So, the best solution is to properly use onStop callback for deleting the location reference and initilize again in onStart.
For more details, check following links:
https://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29
Activity OnDestroy never called?

How to add shortcut on home screen when app gets install

I know it's not the best practice, but it is a requested feature (e.g. for business apps). When the App gets installed, I need to automatically place it on the home screen. I saw a lot of code on the internet, but all of the code only works on button click when the app starts. But I need to place a shortcut on the homescreen immediately after the app is installed and before the app starts. Is there a way I can achieve this?
PS: To make the question more clear: The app will be distributed without Google Play Store, so that's not an option.
Thanks for your help!
Best regards,
Robin
You can't run any code in your application before the user starts your application for first time during to restrictions since Android 3.1. Check this for more information
That's an optional feature of the Market app, not of the apps themselves. When designing an application , it does not receive a broadcast about itself being installed.
the first time the app launched can create it.
You can achieve that by creating a method in your main activity and call this method from oncreate and create a boolean variable andsave it in shared preferences

Methods to be performed when app 1st installs android

Hi guys I have been looking around for the answer to this but have come up with nothing, I would like to have an activity that asks the users for their details and then send them details to an external database after they first install the app. Does anyone have any suggestions on how to create an activity that will only be used when the app is launched for the 1st time. Cheers to anyone who can help
Save a flag in shared preferences that you set after completing the activity. You can actually save this flag anywhere, as long as you have it in some sort of persistent storage. Then on load, check in that activity if the flag exists (you can do this in onCreate), if it does, launch an intent to another activity.
Create a file or store a persistent property at the first boot.
Check for the existence of that file/property at every boot.

Categories

Resources