Reputation: 307
I am trying to modify the app icon in Android programmatically was going through this link here.
This works properly and modifies the App Icon but when it modifies it goes back to the home screen. Can we modify the app icon without going back to home screen automatically?
Edit:
class MainActivity : AppCompatActivity() {
override
fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
val linearlayout : LinearLayout
val button : Button
linearlayout = LinearLayout(this)
linearlayout.orientation = LinearLayout.VERTICAL
button = Button(this)
button.text = "Modify App Icon"
button.setOnClickListener {
NewIcon ()
}
val button1 = Button(this)
button1.text = "Revert App Icon"
button1.setOnClickListener {
changeicon()
}
linearlayout.addView(button1)
linearlayout.addView(button)
setContentView(linearlayout)
}
private fun NewIcon()
{
val manager = packageManager
// Enable new icon first
manager.setComponentEnabledSetting(ComponentName(this@MainActivity, "com.example.appicons.MainActivityAlias"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
// Disable old icon
manager.setComponentEnabledSetting(ComponentName(this@MainActivity, "com.example.appicons.MainActivity"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
Toast.makeText(this@MainActivity, "Enable New Icon", Toast.LENGTH_LONG).show()
}
private fun changeicon()
{
val manager = packageManager
// enable old icon
manager.setComponentEnabledSetting(ComponentName(this@MainActivity, "com.example.appicons.MainActivity"), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP)
// disable new icon
manager.setComponentEnabledSetting(ComponentName(this@MainActivity, "com.example.appicons.MainActivityAlias"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP)
Toast.makeText(this@MainActivity, "Enable Old Icon", Toast.LENGTH_LONG).show()
}
override fun onStop() {
super.onStop()
Log.d ("TAG", "Inside onStop")
}
}
If we see the above code, I am not sure at which line is my app causing the app to background.
If I see any food delivery apps like Zomato where if you have any Membership / license, so based on that it asks if you want to change the app icon? There it didn't went to the background after the app icon changes and hence want a similar experience.
Upvotes: 1
Views: 74