Ui Not updating (Android) - java

I have created a music player app, where when a user plays a song, a services is started and a notification with media control is displayed to the user.
I am facing issues when the user clicks on next or previous button in the notification panel.
When the user clicks on next button, the song changes and starts playing.
The problem i am facing is that, when the song is changed, the Notification UI is updated with the new song information, but my App's player screen is not updating the new song info.
I tried to debug, the data is proper, like the new song info which is being passed to TextView.setText() is correct, also when i immediately print TextView.getText() in the logs, its showing current info, but the UI is displaying old info and not reflecting this new info. The same is happening with other UI elements.
I am using a Manifest declared broadcast to receive Player control actions from the Notification.
When the broadcast receives the message to play next song, it calls the function to change the song, the song changes, the UI data is coming proper, the Textview is receiving it and getText() also returns the new data but the UI is not updating.
Can anyone help me here ? Thanks in advance.

Related

How not to interrupt the current process in the application when the user clicks on push?

on one screen in my application, I am recording audio.
Scenario: User records audio on this screen. A push comes from our application. The user clicks on this push and another push processing activity is launched.
Result: The user loses his session.
Question: what are the options for handling this case so that the user does not lose his session? Ideally, before switching to a new activity, the application would ask the user if he is sure that he wants to go to another screen, because the session will be lost. But how to track it?
Thanks a lot for your advice
The best solution I have found is to clear all old push notifications in the notification shade when going to the recording screen.
val notificationsManager = getSystemService<Any>(Context.NOTIFICATION_SERVICE) as NotificationManager?
notificationsManager!!.cancelAll()
Further during the recording, if a push notification arrives, I receive this in my service inherited from FirebaseMessagingService in onMessageReceived().
If the recording screen is currently open, I do not show a notification in the notification shade. But I show a widget on the recording screen with the push text and if the user presses it I ask if the user wants to go to another screen because the recording will end.
I hope my experience helps someone. Similarly implemented in Intercom

Delay dynamic GUI changes

Activity description :
The main idea is to have an sms sending list and when user clicks the 'Send' button, the broadcast receivers start to receive and GUI changes like highlighting the 'Sent/Not sent' member list, updating progress bar , counting etc
Problems : Activity runs for hours and it's very important to save the exact same GUI change in sync with the user's action on the phone
However I have a few problems and th
The battery is dead/app crash.
Solution : Saving each 'send' state to file and loading it the next time when the user runs the app
The user hits the back/stop button or has an incoming call / Just wants to surf the web.
Solution : Maybe keep running it in the background? by using transparent activity ?
*NOTE : its not about the 'save' state or 'restore' state because everything depends on the broadcast receiver
Ideal way could be
do the backend logic with broadcast recievers + intent service and log the data in backend
Use the activity to just display the UI state based on the saved data.

AlertView that can be shown from background

I have a little problem with an alert View, the idea is that when the app starts, it asks on background for new data for the app, so after receiving the information an AlertView should be shown if there is new data. The problem comes because the AlertView is only shown on the main activity where I launched the asyncTask, so if I'm already in other activity, the alert will appear when I come back to the main activity and the Idea is that the AlertView is displayed in whatever activity the user is in.
My first thought was that the Context that I send to the AsyncTask is the problem so I've tried using getApplicationContext() so the app crashes in the moment of creating the alertView. So I'm, looking for a way to display this AlertView or something equivalent on the screen wherever he is on the app, does any one have ideas?
any idea would be greatly appreciated
you can use broadcastreceiver in every activity which will contineous monitor your background service contineous whenever event occoured using broadcastreceiver display alertbox with content received by receiver.

How to resume from the last screen of the app after the user has pressed home once?

In my app I have a requirement that if the Home button is pressed during the working of app and if the user starts the app from the icon from home screen it must resume from the last activity.
How do I save the last screen history and resume it from the same screen?
The AlwaysRetainTaskState might be what you're looking for.
In your AndroidManifest, in the activity tag, just add
android:alwaysRetainTaskState="true"
Check out following posts:
Android - restore last viewed Activity,
Saving Android Activity state using Save Instance State.

Android Media Player Threading/Concurrency

I am using the default Android Media Player in an Activity, trying to play back a couple of video files. However I have a problem with programming what I want. The desired program outcome would be the following:
A video file is played back
After that, a dialog is shown, asking the user something
A pause of 5 seconds occurs
The next video is shown
and so forth
How am I to program this? Currently, I use a paradigm like the following:
I have a method that sets up the player for theĀ a file, e.g. playVideo(int) So I pass it the first file.
When the player is prepared, it will be started in onPrepared(MediaPlayer).
When the video is finished, the onCompletion(MediaPlayer) listener of the media player shows the dialog to the user by calling showDialog().
The user accepts the dialog. Before calling dismiss() on the dialog, the player object is started for the next file by calling playVideo(int).
This works, but it feels a bit quirky and not clean. And it's of course very procedural. The problems are:
that I can't figure out how to insert a pause after the dialog is dismissed.
that I maybe want to change the presentation order of dialogs and videos and this ain't too easy now
Has anyone got an idea?
For the pause, you could use the AlarmManager to schedule an alarm five seconds from now. It will launch an intent, and that intent could call playVideo(int).

Categories

Resources