I've got a question more about a strategy to use in order to implement the following requirement.
I need to develop a functionality where a user can perform some actions in the application like posting photos, commenting on photos etc. Every of this actions should leave a log somewhere and after entering one of the screens in my app, all the logs should be visible chronologically (the latest first). I've used a TreeSet sorted by item date and it works pretty fine. The problem is to keep this data persistently so that there's a never ending history of logs. I'm reluctant to migrate my code to SQLite unless it's necessary.. I like quite a lot my TreeSet structure thanks to its methods I managed to keep the logic simple. The problem starts when I'm to save this object across different launches of my app....
Has any one any idea how to solve it? Maybe TreeSet is a wrong decision though?
Putting the Logs in SQLite isn't a bad idea. Your other options is to put them in a file, and keep writing to it. You could then write a class to handle sorting it which shouldn't be too bad. The added benefit of using SQLite would be that sorting by Date would be a breeze. But then then exporting it would require the extra work, while having it already in a file makes it easy. So its really just a preference.
Related
Hello I have couple of activities in my app and I want to be able to move between them without to worry that my variable values will get restart every time. I tried to use share permanences but it create my a lot of bugs in the app because they wont go beck to default.
AFAIK your variable values will not be affected As long as you don't finish your activity or explicitly reset/change variables values.If you meant to keep variable values you must use some storage machanism. (File / SharedPreference etc)
Vogella has written very good post on Persistence
http://www.vogella.com/articles/AndroidFileBasedPersistence/article.html#overview_fileAPI
You could begin with things like understanding what a "variable" is. Then gradually move to concepts like classes, attributes and methods. When you get those, try and learn developing for Android - things like life cycle of an application will be of interest to you. After some time you will be able to ask the right questions.
Without all these steps you will not be able to get any help, unless you get someone to rewrite your application.
I have a GCM class, which gets a message that has 2 separate strings from Google GCM server. I need to use those 2 strings inside another activity of my application. The problem is that i do not know in advance how many these gcm messages are gonna be. I need to store these values and use them in another Activity to present them to the user inside a layout. I' m finding this difficult cause first of all, i don't know how many these messages are gonna be, so i can't draw the layout in advance, and secondly cause i haven't found an effective of storing these 2 strings together, so that i am able later to manipulate them.
Each group of these two strings, belong to a user and should be stored in a way so that they can be retrieved separately from other group of strings.
I have tried to do this by using SharePrefrences or intents but i can't find a proper solution to this.
I know my question might seem silly, and i am not asking for a solution, but i am stuck and i would be really glad, if someone could give me some advice or guidance on some workaround to this, or where to look..
You should be able to store them in an ArrayList or HashMap and send them through an Intent. You won't need to know how many there are, just use a loop to add however many exist into the list. When showing them, you can use a ListView to show them so you don't have to worry about knowing how many there are each time but you can get the count so you can know if needed. Other than that, its hard to say without seeing what you have tried, what is/isn't working/ or what you already know so I have added a few links which may be helpful in understanding these objects
ArrayList
HashMap
consider LinkedHashMap if you are concerned with the order of the data.
I'm very new to coding and have searched everywhere but havent been able to figure this one out.
Im trying to create a Lap Time Leader Board for various tracks in a video game guide. The user needs to be able to Click on the track name and then inside of the new layout "Create" a new time...that needs to allow him to imput the Car and the time it did on this track, then it needs to either sort itself or be manually sortable so that the times are in order from fastest to slowest. While i can build the layout easily i get stumped there.
How can i make it so that when the user clicks "Create New Time" the code gives him the spaces for time and car model.
How can i make sure it saves the correct info with SharedPreferences since each time will need to be saved differently (i think this has to do with the name and then ++ but i could be wrong)
How can i make it sort itself or be sortable for the user.
Can someone show me some sample code that does this? I dont know much of anything about SQL and would prefer not to use it if i can avoid it.
Im sorry this is such a noob set of questions but this after trying the notepad tutorial on AD and numerous video and book tutorials i havent found what i need to make this a reality.
You can always use a the Dialog class to create a pop up dialog to allow the user to input the information you are looking for. Sorry that you wish to not use SQL
Shared Preferences isn't such a good idea because you will have to do a lot more work to code your desired affect. A datatbase with simple Relations(tables) will suit your needs as opposed to Shared Preferences where you'd have to get creative to have the same data structure. Such as an ArrayList of BasicNameValuePairs, that could be a head ache. Database is the way to go, you can do everything you need if it's properly set up.
Sorting is quite easy in Java as you could always use the Collections class and implement the Comparable interface to compare your lap times to each other and sort them by total time. For a display such as that you would want to look into a TableLayout in Android XML. Don't worry so much about that, the Eclipse IDE will let you easily create and populate it. This would involve loading your laptimes from your database into a List and sorting them by time. It's a bit tricky but easy once you understand the Comparable interface and Collections if you need it.
If you need more insight post a comment, just wanted to share some ideas on how I would approach it.
My project is a visitor app for a University, that basically displays places and events on a map, and allows the users to interact with one another by making posts with advice/recommendations/questions and so on.
So far I've been trying out bits of code seperately (lists, tabs, the basics), following the android tutorials and trying things for myself. My problem is that I'm not sure how to combine all the bits of code into one project.
I know that I need to make a database, and a map (using OSM rather than google).
The database will store information on places, events, and posts that users have made. With co-ordinate information because they need to go on the map. This information is also displayed in seperate tabs - e.g. a list of places.
My problem is that I don't know how this will all fit together.
Will I need seperate classes for the database, populating the lists, and displaying on the map? Or can they all be in a single class?
I'm a little hazy on how the classes and activities are going to communicate, too. At the moment I'm thinking the database object is going to get passed to the listviews and mapview, which then take and display some of the information?
Any advice on how to cobble these elements together would be much appreciated. :D
I think I will need to subclass SQLiteOpenHelper for my database, so it'll need to be its own class?
I'm thinking of using OSMdroid for the map, which I'm not sure how to do yet.
And everything needs to be inside a tabview.
Welcome to StackOverflow!
Your question is very vague and broad, and likely to get closed as "not a real question" - I suggest you take problems one by one and ask specific questions as you go along and run into problems. Try to think about your problem in these terms: what's the minimal thing I need to get it to do the thing I want. Keep in mind that ANYTHING you want to do is possible, the main question to ask yourself is: what do you want your application to do exactly? Think about the number of different screens (activities), and how they would communicate to each other (when you click XXX, that will lead you to YYY, and so on). One advice: start simple, it's very easy to get buried in too much complexity, especially since it's your first project. It can quickly become very complex, even with a simple concept.
As you didn't specify your level of expertise in coding, it's difficult to give precise advices: but coding an android application is not very different from a "regular" application, with a web or Swing or C# user interface. So I would advise you to learn about OO programming in general, things like composition, inheritance, encapsulation, dependency injection, unit-testing, etc.
Then start writing a base Activity for your main view, write its layout, and add views and graphical elements to it. Then add the listener code for your widgets, that will generate Intents to other Activity.
Then add a DatabaseHelper when you want to save stuff in a database (that can come later, to begin with, you can just "stub" the interactions to a database, by writing what you would save to db on screen using Toast for example).
All objects can be injected into other objects by passing a reference to them, either at construction time or through setters.
Sorry not to be more precise, as I said it's a very vague question.
I have an idea to let users translate my application to their own languages.
I imagine this in this way:
If application is not translated to user's system language, English version of UI is displayed and user is asked for help in translation (it's obvious)
Next, user is asked for translate some phrases from English to his mother tongue. And asked to check some others translations. (it's a bit of work, but nothing sophisticated)
Hard part of my idea is:
User presses "update translation" and text resources for this application are update to latest editions.
Of course it's possible to make frequent updates, but this approach has some disadvantages:
1. I have to make all of those updates frequently, and not all of users will be happy with it.
2 Even if updates will be done weekly, time from make effort to get results will be too long form most of users, and probably, response will be not as good as it can be.
Have you any idea how to load translations "on-line"?
Android currently doesn't support this. To accomplish what you want, you'd need to insert your own resource handling code to return strings everywhere they are used in your UI. This means you couldn't let the framework load strings itself (for example no use of android:text="#string/something" in your layouts), and calling your own function to retrieve a string that wraps Resources.getString()/getText().
And you'll also need to deal with the fact that resource IDs are not stable and can change with every build of your app.
So you are looking at something quite non-trivial.
I have done some internationalizations using:
launchpad with android2po
getLocalization
I will first check if they have some kind of api. If there is no API, I would check the gettext's java implementation and handle translations with it.
You could cache any of the current user's translations in a file on the SD/storage, and show it to that specific user. Then, when it gets its weekly update, remove the cached file and start again?