Categories
Mastering Development

Media Player has not been initialized but song is playing

I added a song to my app using MediaPlayer, like that: class BackgroundSongService : Service() { private lateinit var mediaPlayer: MediaPlayer private var length = 0 override fun onBind(p0: Intent?): IBinder? { return null } override fun onCreate() { super.onCreate() mediaPlayer = MediaPlayer.create(this, R.raw.bonte_song) mediaPlayer.isLooping = true mediaPlayer.setVolume(20f, 20f) } override fun onDestroy() { mediaPlayer.stop() […]

Categories
Mastering Development

handling onError() calls with speech recognition

i have a LifeCycleService that tries to record infinitly and somehow it gets stuck after one recording when onError() is called with errors 5/6/7/8. how can i deal with that and manage to record infinitly? *dont relate to all of my snippet as it may confuse you. You can see that i call prepareVoiceRecording() from […]

Categories
Development

Best way to send notification if new message is received while app is killed or in background

So, I have a chat app that is using Firebase Realtime database. Everything is working as expected, the problem is, whenever the user kills or sends the app to background, new messages received don’t send notifications to the user. I’ve searched StackOverflow for a solution to this problem but I couldn’t find a working solution. […]

Categories
Development

How to set GIF to run smoothly while code is executing behind?

I have an Activity which needs to display a GIF while some heavy stuff is happening behind. I’m not refering to spash screens. The Gif is in the same layout as other views. Usecase: 1. Activity Starts and I set view visibility, where the GIF stands, to TRUE 2. Forground service starts and some requests […]

Categories
Development

Dependency injection with IntentService doesn’t work

I want to create TCP_Client which sends data to server in many activities. I decided to use Dependency Injection to inject all samely configured clients to all clients. Unfortunately it stops working on start. My application module val appModule = module { single<ConnectionService> { ConnectionServiceTcp(“192.168.0.1”, 8888) } } Main Application class MainApplication : Application() { […]

Categories
Android Development Kotlin

Android Studio – Kotlin – How to make the reference to the service null?

I’m trying to adapt Google’s LocationsUpdatesForegroundService example into Kotlin to use in my app. Now, everything is going fine, until I need to make a reference to a service equal to null. That doesn’t ’cause any problems within the Java code it originates from but, when I try to implement it in Kotlin, even if […]

Categories
Development

App keeps running when foreground service is stopped last

I came across a behaviour in Android’s process management in conjunction with foreground services, that really confuses me. What is reasonable for me When you swipe your app from ‘Recent apps’, the OS should finish the app process in the relatively near future. When you swipe your app from ‘Recent apps’ while running a foreground […]