How to identify the click event in the application launcher icon in android? I need to go to home screen once the user click on this icon. For example, assume this is the manifest file:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
..........
Using the following code segment in main activity inside onCreate()
actionBar=getActionBar();
actionBar.setHomeButtonEnabled(true);
the application icon is click-able .I don't' have any way to detect the click event of this. Is this possible to do in android. Any suggestion to do that?
You have to override onOptionsItemSelected(). Try this:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// do what you want to be done on home button click event
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Additional details check on Android Developers: "User Interface. Action Bar".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With