@Pablo-J-Rogina Yes, I know how to implement it. It is in the guide. I'm just wondering when I have to use this approach and when not.
@mvuori Thank you. In Qt it is quite clear for me what is UI and what not. If my application isn't in foreground, I don't touch the QML part. In Android it isn't that clear.
If you check the guide, it describes how to set SD card (un)mount listener. I would say this has nothing to do with the UI.
I'm wondering if my approach to show foreground service is correct or not. Currently I use this method to show it:
public class MuzikaServiceOld extends QtService
{
private Handler handler;
@Override
public void onCreate() {
super.onCreate();
handler = new Handler();
}
public void showNotification(String text) {
runOnUiThread(new MyNotification(this, text));
}
private void runOnUiThread(Runnable runnable) {
handler.post(runnable);
}
}
The class MyNotification in the run() method creates and shows the notification. The question is, if this is a correct solution, because I create a new instance of the notification each time I change it.
The second possibility is this:
public class MuzikaServiceOld extends QtService
{
NotificationManager mNotificationManager;
@Override
public void onCreate() {
super.onCreate();
mNotificationManager = new MyNotification(this);
}
public void showNotification(String text) {
mNotificationManager.update(text);
}
}
This works too but in this case I'm not showing and updating the notification from Android UI thread. But I don't create a new instance on every change.
So the question is, which of these two solutions is better and which can lead to some problems. I hope this example explains better my question.