Application Architecture
-
Hi all; I must start this discussion with three statements. (a) I am one of those who learns by doing (b) I have a basic understanding of Android programming (c) I am a .NET developer (ie: I know how to program). What I seek is advise on how to go about developing an application I have in mind. This application will be running in the background (therefore a Service) periodically polling a URL to check for new messages. If a new message is found, a notification or toast is displayed. So far, so good. I think I know how to do all that. The service will start automatically at device boot up. This, I think, I have also found how to do. The problem I have is that as part of the same application I want a UI which the user can then use to process the received message/s. How do I go about implementing this within the same app. The aim is to have ONE installation package. I do not think what I seek is rocket science. I would appreciate any notes or links to relevant guides or tutorials. Regards Eric
-
Hi all; I must start this discussion with three statements. (a) I am one of those who learns by doing (b) I have a basic understanding of Android programming (c) I am a .NET developer (ie: I know how to program). What I seek is advise on how to go about developing an application I have in mind. This application will be running in the background (therefore a Service) periodically polling a URL to check for new messages. If a new message is found, a notification or toast is displayed. So far, so good. I think I know how to do all that. The service will start automatically at device boot up. This, I think, I have also found how to do. The problem I have is that as part of the same application I want a UI which the user can then use to process the received message/s. How do I go about implementing this within the same app. The aim is to have ONE installation package. I do not think what I seek is rocket science. I would appreciate any notes or links to relevant guides or tutorials. Regards Eric
I'm not entirely clear what your question relates to. Are you asking how to build the UI or how to process the received messages? Can you clarify what you need help with. What are you trying to achieve?
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
-
Lots of excellent tutorials at http://www.codeproject.com/KB/android/#Android+Tutorial+Contest[^].
-
I'm not entirely clear what your question relates to. Are you asking how to build the UI or how to process the received messages? Can you clarify what you need help with. What are you trying to achieve?
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Hi Dominic; What I need to know is how to build ONE application that starts automatically as a service, but has a UI which the user will use when the service raises a notification. Which activity will have broadcast, be a broadcast receiver, etc.... Thanks Eric
-
Hi Dominic; What I need to know is how to build ONE application that starts automatically as a service, but has a UI which the user will use when the service raises a notification. Which activity will have broadcast, be a broadcast receiver, etc.... Thanks Eric
Create an Android Application project, register a Broadcast Receiver with action
android.intent.action.BOOT_COMPLETED
in the Manifest file.<receiver android:name=".MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>Then start the Service from the
onReceive()
method of the Broadcast Receiver.public class MyReceiver extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) { Intent i = new Intent(context, MyService.class); context.startService(i); }
}
Create an Activity with the desired UI and pass that Activity as Pending Intent to the notification.
Intent intent = new Intent(this, MyActivity.class);
PendingIntent launchIntent = PendingIntent.getActivity(context, 0, intent, 0);When the user taps on the Notification, the Activity used to create the
PendingIntent
is started. P.S. - You can have Service, BroadcastReceiver and Activities all in one project. -
Hi Dominic; What I need to know is how to build ONE application that starts automatically as a service, but has a UI which the user will use when the service raises a notification. Which activity will have broadcast, be a broadcast receiver, etc.... Thanks Eric
I've done something similar that may give you some ideas. The application I worked on previously polled for updates from a web service. The class that did this background polling was based on the Service class. When a data update was detected from the web service, it would populate the database with the new data. Do you know what your trigger is? You mentioned that you are polling a URL? Are you polling a web service for updates then? How do you know when you need to trigger your UI?
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
-
I've done something similar that may give you some ideas. The application I worked on previously polled for updates from a web service. The class that did this background polling was based on the Service class. When a data update was detected from the web service, it would populate the database with the new data. Do you know what your trigger is? You mentioned that you are polling a URL? Are you polling a web service for updates then? How do you know when you need to trigger your UI?
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
Hi; The trigger will be a field in the data received from the webservice. When a trigger is received, a notification/toast will be displayed and then it is up to the user when to open the UI to check the full details what was received. Like the GMail app: you are notified when an email is received but you decide when to open the app to read the email. That part I have it sorted and planned and is something I had implemented on Windows Mobile (in another life). What I need to know are the steps (and Objects to inherit from) required to do it in Android. My mind is not yet clear about the intents/broadcasts/etc.... Thanks again. Eric
-
Hi; The trigger will be a field in the data received from the webservice. When a trigger is received, a notification/toast will be displayed and then it is up to the user when to open the UI to check the full details what was received. Like the GMail app: you are notified when an email is received but you decide when to open the app to read the email. That part I have it sorted and planned and is something I had implemented on Windows Mobile (in another life). What I need to know are the steps (and Objects to inherit from) required to do it in Android. My mind is not yet clear about the intents/broadcasts/etc.... Thanks again. Eric
Presumably then when the user sees that they have a new notification, they open your app to view the details. So it should just be a case of invoking your UI and displaying the most recent notification. Maybe you could add a flag so you know which notifications have been opened / read, and highlight those in some way. I'm not sure what data you are displaying, but maybe you could display your data in a grid format, in which case you'd need to define an Adapter. I wrote an article about Android adapters that you may find useful Displaying Data with an Adapter in Xamarin.Android and Visual Studio[^]
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
-
Presumably then when the user sees that they have a new notification, they open your app to view the details. So it should just be a case of invoking your UI and displaying the most recent notification. Maybe you could add a flag so you know which notifications have been opened / read, and highlight those in some way. I'm not sure what data you are displaying, but maybe you could display your data in a grid format, in which case you'd need to define an Adapter. I wrote an article about Android adapters that you may find useful Displaying Data with an Adapter in Xamarin.Android and Visual Studio[^]
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
-
Hi Dominc That is Xamarin. I am trying to keep to Java and basic Android for now. Thanks Eric
I know you are using Java but the classes / objects are the same. Only the syntax is different, but Java and C# are similar enough that you should be able to leverage my example code into your own application.
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare
-
Hi Dominc That is Xamarin. I am trying to keep to Java and basic Android for now. Thanks Eric
I think you already have an answer here - read the one posted by gupta.avinash or refer to the article - Article 10 - Beginner's Guide to Android Services[^]
-
I know you are using Java but the classes / objects are the same. Only the syntax is different, but Java and C# are similar enough that you should be able to leverage my example code into your own application.
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare