I'm not new to Java or databases, but I am new to Android app development. I have an app idea and have started to put it together. It's a very simple game that I would eventually like to have multiplayer capabilities.
The part of this process that I am pretty clueless about is the backend portion of the application. I need a database that will store things like usernames and passwords, scores, and things of that sort. I will also need to store things that I will need for the game in here. The application will rely very much on the database and it is important that any device has access to it and they are all looking at the same data.
If I've done my research right, this means that a simple SQL Lite database on the device itself isn't going to help me. Ideally, I would use SQL Server and create the database, as that's what I use for other projects... but I have no idea if this is possible or ideal.
I really just need somebody to steer me in the right direction here. I want something simple that can be accessed easily by any device at any time.
You'll want to write a server application which the various clients connect to. This server would be responsible for processing information given to it by clients and returning appropriate data back.
Exposing the database directly would be unwise; it would allow inventive players to cheat your system (or worse!) because they would have unfettered access to anything your application does. Your own server application can ensure that only reasonable access to the data store is permitted.
As for how you implement it, there are any number of choices. Web services are popular these days (in which case ASP.NET is the likely fit with SQL Server), but you can implement your own, non-HTTP, game protocol if you'd like.
You could access remote SQL database from Adnroid app using JDBC.
I've provided example here: How to save image files to mysql with sql code and how to display them with java?
The only difference I've encountered using JDBC in desktop and android apps that in Android You have to perform JDBC operations in a separate thread, like any other network operation in Android.
Related
In the company where I work we have, among others, an application made in Java running on two places (let's say Merida and Coatza) and both have different databases. The users from Merida only occasionally used the program to get some info or capture things. Now the company owner decided to control almost everything from Merida but we cant get the databases merged due to operation logistic.
The thing is that when the application uses the persistence-unit to connect coatza it's incredibly slow since the app its not prepared to use remote databases (at least not with a high performance).
I thought of something like teamviewer to run the app remotely but not the database, however I don't want to run the complete desktop, only the application. Or develop a part of the program on JCurses so it can be run from coatza but there is not enough documentation and we use a lot of tablemodels.
Is there something I could do?
The application is a DesktopApp. We use Jboss 5 as server. Hibernate and JPA.
I had a similar situation where we needed to use the same application at different locations because the license was too expensive. I used a feature called RemoteApp on Windows Server 2008. The best part is that you can have a desktop shortcut for any app on a remote computer and all you need to do is open it and login and only that particular app starts running instead of the whole desktop. There is also a web interface for remoteapp so that you can simply login and select whichever app you want to run. For more details take a look at http://www.techotopia.com/index.php/Configuring_RemoteApps_on_Windows_Server_2008
I'm developing an android app that accesses Databases that are stored on a server machine. I've done a bit a of googling and had a look through some of my programming books but can't find much information.
SQLite seems like the right way to go but I can't find anything about Databases stored on a server. I'd appreciate it if somebody could point me in the right direction.
Thanks
What kind of server you are talking about?
The simplest case is that you can write a server program to expose some information in your database. Then, you can do a GET request from your Android app to get those data.
If data is more complicated and structural, your server can return json or xml object, then parse them from your client.
I have an SQLite database stored in the assets resources of one application used to load UI and other stuff into the app, mainly just holding text nothing out of the ordinary. I want to be able to get a writable version of this database so I can modify it from another application.
Example:
First application is on the market with limited number of enabled features. User gets to a certain point where they need to buy extra content to do more stuff in the app. The original app has these features but they are not enabled in the app using the database. I want the user then to download a second app from the market which is just used to change one field in the database from disabled to enabled thus unlocking the new features.
I have an idea I may need to use content providers but my understanding is once created they are accessible to all applications. I need it, for piracy reasons I guess, to only be able to communicate with apps signed off by my key.
Thanks
Sam,
I understand what you intend to do, but you are going about it the wrong way. Your 'Unlock App' would not be able to modify the Database in the assets folder of your 'Free App'. That's just general android security model stuff.
You may want to look at this question: How can I use the paid version of my app as a "key" to the free version?
It describes how you can create a 'Unlock App' on the market to unlock features of your 'Free app' without needing to actually modify any of the original data in the 'Free App'.
Good luck
I am creating an android app that is basically a listing of information on Mushrooms. I get this information from an sqlite database. I have a global singleton with a services class inside it in which I use to access my db. Almost every activity accesses the db. Is it better to leave my db open all the time or open and close it as I need the data?
If the best practice is to leave it open all the time, where do I need to make sure to close it and what is the worst case scenario if I left it open when the activity was destroyed?
Your best option here is to refactor so that your application accesses the database via a ContentProvider. Your ContentProvider implementation is the only thing with a handle to the database open.
This gives you several advantages:
only one thing has the database open, so your problem just goes away.
lots of standard support classes to automate stuff like database management.
better integration with the standard Android list-management views, which are all designed to work automatically with cursors provided by ContentProviders.
All your data can be addressed by URI (typically of the form 'content://com.fnord.mushroom/mushroom/43'), which means that other applications can access your data too.
Using a ContentProvider, it's possible to glue three or four standard classes together to produce a browser interface to your database and never actually have to write any real logic.
On the negative side, ContentProviders only really support access via a limited interface --- in SQL terms, you get INSERT, SELECT, UPDATE and DELETE with no nested clauses. If you're doing complicated SQL stuff it can be a bit painful to route requests from your app to the ContentProvider and back again. However, most people don't need to do this (and if you do, custom intents are the way to go).
I would open the db as needed. That way you know for sure the connection is closed once the particular activity that opened it is finished. Although Android has built in checks to make sure it closes upon application termination, it doesnt hurt to be on the safe side. I'm also guessing having it open all the time could cause leaks or something.
Based on my past experience in Java I would say it is better to close the connection, it probably doesn't matter in a small Android application, but if you have 10 applications running and all of them access the database, you have 10 pending connections. Start a few more and sooner or later another application will have to wait because the SQL server can't handle any more requests.
I guess you could think of it as a file on your computer. You read data from it, and then close it when your done. Why keep a file open in your application?
Now I'm very new to Android programming so I haven't got around to implement database calls. But when I faced the same problem in a Java application a few years ago I implemented a database object, in which I had the connection to the database. "Everyone else" (the classes) had to call the database object (singleton or final methods) to get data, sort of like stored procedures but in the application instead.
Because of this I knew when the calls where made and when they stopped. I then put in a timeout, so as if nothing happened in a few minutes, I would close the connection to the db. (This also took care of some timeout exceptions because the timeout of the connection would never happen.) When a new call entered, I could easily start a new connection and use the new db connection.
Basically I abstracted away SQL calls by having methods as public Fungus[] getAllFungus() and public Fungus[] getFilteredFungus(string where).
I am confused about the approach for application that am writing. I have developed the application jar and will be distributing via java webstart.
Now i need to putup a website supporting my app.
doubts i have
1)Can i pass this username and password to the jar that i will be launching?
2)Can the webcomponent calculate the time for which the app was launched.
Basically i need to understand how will the webcomponents and my java app interact with each other in terms of any data required to pass to the app and any info retreaving from the app and putting on the web.
Thanks
Krisp
I want to pass arguments like username to the JNLP and then want to pass it to the main class.
Is there any direct way to do so rather than use database?
since JNLP is just an xml file. I could not find a direct way to do so.
Can i anybody refer me some working code example.
Database is probably your best bet for sharing data between both apps. Other options are web services, sockets, RMI, etc.. You will probably need to look into all, on the surface initially, to know what suits you best.
As for the Calculation of the time in my java app i can use currentTimeMillis() to calculate the time for which my app is running.
But senarios like app getting crashed or forced termination of the app it will not get saved.
Any Hints for communication in terms of data between the web and Application jar?
Thanks
Krisp