Android one time tutorial - java

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!

Related

Firebase Jobdispatcher - to use or not to use

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.

Data deleted upon application exit

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.

Java update panel for all users upon database change

So I have a program that runs on multiple computers. The program connects to a server where it gets all of its data from. There's a JPanel which lists names from a table in my postgresql database. As of now, the only way to refresh the panel is with a button press. I want the panel to update on its own when there is a change in the database so if one user adds a name, the other users will be able to see the change right away. Is there a way to broadcast a message to all users that are connected to the server so that their panel can refresh?
As soon as you want to do something like this you enter the world of multiple threads and all kinds of havock. Your question does not really have anything to do with databases, you merely want to send a message to all others using the application to update a component when they need to, keep your concerns separate. Now then you need to ask some questions like are the users all on the same network? Then you can get away with a simple chat client for java, there are heaps of them out there. But think about it, do you really need this requirement? Can't you just update the table say every 10 seconds? Or every 5 seconds? The difference in the difficulty of the implementation is substantial but the result I would say would be very similiar, unnoticable to the user even. But maybe you just want to learn stuff, then maybe you think you should add another table in sql with one entry which records the time the user table was updated which you can check and will be more optimal than the other. But this is considered bad practice, do you care? Same with sql statements to check when a table was edited last from what I have seen on the net, but should we always apply best practices, the application will still get across the line.
Maybe your update button is not looking so bad after all.
But users complain about that sort of crap and you can't explain this stuff to every user. My suggestion would be to have a configurable update that runs every how ever many seconds you tell it to. You will have to look up stuff about multi-threading though but shouldn't be too horrible.

Saving and Viewing/Editing data in Android

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.

How do I save chronometer elapsed time in android app

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.

Categories