Commit 081555f3 authored by Nihar Thakkar's avatar Nihar Thakkar
Browse files

Un-bind InstallManagerService when MainActivity is destroyed

parent 7e5420c4
......@@ -34,6 +34,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
private val searchFragment = SearchFragment()
private val updatesFragment = UpdatesFragment()
private val settingsFragment = SettingsFragment()
private lateinit var serviceConnection: ServiceConnection
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -61,7 +62,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
startService(Intent(this, InstallManagerService::class.java))
val blocker = Object()
var installManager: InstallManager? = null
bindService(Intent(this, InstallManagerService::class.java), object : ServiceConnection {
serviceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName, service: IBinder) {
Messenger(service).send(Message.obtain(null, 0, { result: InstallManager ->
installManager = result
......@@ -72,7 +73,8 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
}
override fun onServiceDisconnected(name: ComponentName) {}
}, Context.BIND_AUTO_CREATE)
}
bindService(Intent(this, InstallManagerService::class.java), serviceConnection, Context.BIND_AUTO_CREATE)
synchronized(blocker) {
blocker.wait()
}
......@@ -139,4 +141,9 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
Toast.makeText(this, resources.getString(R.string.error_storage_permission_denied), Toast.LENGTH_LONG).show()
}
}
override fun onDestroy() {
super.onDestroy()
unbindService(serviceConnection)
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment