I’m rather new to Android and I’m working on an app that is registered to a broadcast receiver. Whenever an event is trigger, I’d need to request some input from the user and do some action based on his answer.
From what I’ve been reading, the usual way would be using an activity as a dialog, so whenever an event happens the dialog is displayed like a popup (even when my app is not active). This looks fine though I’m still not very convinced as I find it a bit too “intrusive”.
I was thinking of using a custom notification, by means of RemoteViews. From what I’ve read this looks ok though I haven’t been able to see how to include buttons on such notification. I tried adding a button on a custom layout and passing it to the remote view. Even though the button is drawn in the extended view, whenever I click on it the whole notification is clicked. I was wondering if it would be somehow possible to create a notification with two buttons and react accordingly?
Otherwise, any better alternative?
Thanks in advance!
If you want it to be unobtrusive you can create a BackgroundService that displays or changes a notification icon (in topmost bar) when user input is required. You could also turn on the short vibration or a sound signal, as per user’s preferences . The user would then simply down-drag the notification bar and click on the application icon, which could then display any kind of activity.
Also, if your app won’t be the topmost app AFAIK you must create a BackgroundService because it’s the only way to stop Android from killing your app when it’s not active (any app that’s not topmost is a candidate for suspension or termination when resources are low, AFAIK).