I am a new to developing for Android and have been reading up and researching in order to become more familiar with the platform. My programming knowledge is moderate I have experience with C++ and a fairly proficient with Actionscript 3.0. I picked up programming primary to work on game development but come from a more artistic/design background.
I have a relatively simple idea for an app that I want to approach from the most practical way possible seeing how it’s my first attempt. Essentially the core functionality of the app will be drawing information I will be getting from an ephemeris chart. At a certain time in the day which is based on the data from the chart I want to change an image/display information based on that day. I am trying to wrap my head around the best possible way to do this. Also I would like to give the user an option of having a notification of some kind when the change occurs, but that is something I have come across in terms of basic implementation.
So my question is if you were to approach setting something like this up how would you? What I am not sure about is setting up a time element so the application knows when to change the image/data to display.
If you took the time to even read this I really appreciate it.
Wade.
It really depends on where/when/how this image is displayed. I will assume that the image is shown in a normal
Activity:Look into using the
AlarmManagerto set alarms. These alarms could start aServicethat changes the image source (perhaps updating a db entry of the image resource or filename). Once the work is complete in theService, send aBroadcast(orStickyBroadcast) with the results in aBundleusingIntent.putExtra(). You could also set the status bar notification at this point using theNotificationManager. ThePendingIntentof theNotificationshould be theActivitythat shows the image.Check out the “Alarm” and “Notification” sections of the APIDemos (
/samples/android-8/ApiDemos/src/com/example/android/apis/app)UPDATE: A more robust Alarm system is Mark Murphy’s
WakefulIntentServicefound here.Then, register a
BroadcastReceiverin thatActivity, listening for theBroadcastIntentthat you set in theService. This will listen for when the service completes. If you use aStickyBroadcastin yourService, the data will be cached, making it available when theActivitycomes to the front of the stack. Otherwise, you will need to persist the data (in an SQLite db orSharedPrefernces) and use a timestamp.UPDATE – Demonstrate persistent data storage:
A great place to start with learning SQLite is the Android Note Pad demo. This will teach you many of the key aspects of Android including life-cycles,
ContentProviders(db wrappers), and using AndroidViews(widgets).The alternative I mentioned is using the Application’s default
SharedPreferences. A simple example of usage is this:Hope I understand you correctly, and that this helps.