I have an android application which is actually an indoor positioning system, using a SQLite Database. When the user opens the app, he has to calibrate it first. That is, scan position in the venue then app records rssi x,y values in a sqlite database THEN it shows the user's position. However when i exit the app, and open it again, i have to go through the whole process of calibration.
The data is deleted from the database which forces the user to re-calibrate it every time he/she starts the application. Anyone can help me prevent the deletion of the records please ? Thank you.
This is because it is a short lived object. When you close your application,that object is recycled in the onStop method of the activity. If I were you, I would consider storing the calibration settings in either a SQLite DB or in the shared preferences DB so the user does not need to constantly recalibrate. The implementation really depends on what needs to be stored for the device to be calibrated.
This link should help explain activity lifecycles:
http://developer.android.com/training/basics/activity-lifecycle/index.html
http://developer.android.com/training/basics/activity-lifecycle/stopping.html
You'll need to override the Method onSavedInstanceState() method.
Please see this question, where that is described in detail.
Related
I am developing an App, a simple, but hopefully addictive little game. The user has to solve predefined levels, as quick as possible.
Information on the levels is stored online in an MySQL database, which also contains the average time it took all players to complete a given level. Also, the level-data is stored, locally, in a SQlite database on the phone.
What I want to do is the following. I want to synchronize the average time (from server to phone) and upload the time it took a player to complete a leve (from phone to server).
Ideally this happens each time the player starts the app or finishes a level. For this, I am considering a Firebase Jobdispatcher, but I was wondering if this is overkill or not. For your information: it is not the end of the world if the average time stored on the phone is not entirely up to date. The game will work just fine without it being up to date. On the other hand, I want it to get updated regularly as the performance of the user will be compared to the average time.
I am a beginner, who wants to do things correctly. Hope you can help.
It sounds like you already know when some work should happen. As you said:
Ideally this happens each time the player starts the app or finishes a level.
You don't need JobDispatcher to schedule work when you are already in control of the times when the work should happen. JobDispatcher is used when you need to schedule some work at some point in time or interval when your app may not even be running.
I want to make and app with widget to present some data,and i want to be sure it will not become a battery drain source and add all the checks i have to,so there is no problem.
So android documentation actually says that ACTION_APPWIDGET_UPDATE may be sent in response to a new instance for this AppWidget provider having been instantiated, the requested update interval having lapsed, or the system booting.
But i came into this bizarre answer here
Android widget update called twice after device boot
that suggest that the home screen can actually update your widget n times at will.Seems bizarre,and i cant find something similar,do i really have no control over this?
As in the previous answer you found, there is no way to limit how many times the home screen might update the widget - it is responsibility of the homescreen and you cannot control this.
You could add a limit in your update implementation instead. For example, record the time the checks are made. If the widget update is requested again too soon after the last one, ignore it until the required amount of time passes.
I am trying to design an app and am really new to both coding and android development.
In my app, (a homework planner that uses SQLite Database), I want a screen to prop up once, the first time the app is launched, where the user enters a number of classes (such as math, english etc).
Anyone know how I can accomplish this? one of the main problems is how to have a screen that only runs the 1st time and then never again.
Thank you!
You could use SharedPreferences to store an attribute like 'firstTime'.
The first time the application is opened, you could alter the value and check it everytime the app is opened.
You can check your database, if the user entered a number of classes. If he dont, show this dialog, else not.
There are many other ways you could solve your problem!
I have been working on an app that can save your passwords for you. I would like it to work similarly to a contacts application. For example, I want to have a screen that displays all the names of the passwords entered (like the names of your contacts), then when you click on the name, it takes you to a screen with all the information you previously entered on it (like the phone numbers/email addresses that would be in your contacts). I also would like a way to edit this information. I have been searching for almost 2 weeks now and have found nothing to help me. If someone could simply point me in the right direction, or tell me what this way of saving information would be called so I can research it, it would be GREATLY appreciated. If possible, could any answers be explained well enough that a fairly new developer could understand them.
I think you need a ListView and some Adapter to show the name of the password, and when you click one of them, you create an Intent which leads you to a new Activity which show the associated details. In the detail Activity you can do some editing job and save them to database or ContentProvider.
If I am right, I think you need to follow the tutorial of Android development to learn more about Android system.
I'm developing a sort of parking meter counter app for a few specific locations. The app asks the user where he is (dropdown menu, saves column letter and number, like A6) and then shows a screen with the given location, a timer (chronometer class) counting up from 0 and the price that has to be paid on exit (calculated using elapsed hours * base price).
This all works nicely, until the user or the OS kills the app (task manager or memory management). Then, the next time the user opens the app, he's back at the main menu and his location, time and price has been lost.
I need a way to save all of the user's information and be able to load it up on app restart.
Initially I had thought to save the user's location and the exact time the chronometer started (DateTime.Now() maybe?) to a .txt file in the internal storage so that it would read:
mallname,columnLetter,columnNumber,startTime
This way, if the app is killed, or any time the app is started up from scratch, the MainActivity will first check if a file.txt exists in the app's internal storage, if it does, it immediately starts the lastPage activity, reading the .txt file to pass the values as parameters (thus, the comma separation). If there's no such file, it would just carry on normally. The last page does contain a reset button that would delete the file so that the app can start up normally the next time it's used.
I don't know how efficient this method is, but it's the first thing that came to mind. However, I don't know how to go about this. I have this same exact method programmed in C# for Windows Phone, but I don't know how to translate it into Java for Android. Also, in C# I didn't actually use a chronometer, rather, I had the startTime saved and used a timer that would calculate startTime - DateTime.now() on every tick (every second) and update the textBlock to show this.
Any help would be greatly appreciated.
Usually user data should be saved to a SQLite database, however in your case, since you're talking about a few variables, it'd be much easier for you to save these values in the application's SharedPreferences.
For every value you'd like to save, add this line to your Chronometer's onChronometerTick() method:
PreferenceManager.getDefaultSharedPreferences(this).edit().putInt("your_key", <Your_value>).commit();
This can later (whenever your application recovers from a crash, for example) be retrieved by:
PreferenceManager.getDefaultSharedPreferences(this).getInt("your_key", <Default_value>);
Regarding performance issues, if your Chronometer ticks once every second this should have no effect on your app's performances and is completely acceptable.