Can We write an event for clicking App Icon. I need to display a string during the Application icon click. Can anyone help on this. Thank you.
Asked
Active
Viewed 243 times
1 Answers
0
Firstly the question is where you want to display your string. As you didn't mention developing a widget or anything else but an Android app, my guess is you want to display it in your app.
So the closest convenient callback to the start of your app should be the onCreate method of your Application class. For this, you will need to extend the application class. You can see how to do it here: https://medium.com/@balakrishnanpt/android-application-class-a8a1d64c82d1 At this point, you will be limited to showing a Toast message as you don't have any Activity yet.
As an alternative, you can create your first launcher activity and display your text in it's UI from the activity's onCreate method.

Gegham Kurghinyan
- 21
- 2
-
Thank you. I am doing one application, which installs another application. For example I have Application A while installing Application A It will install Application B from A. When I click the Application B launcher icon on home screen It should not open and Should display a toast message that " Please Open Application B from A". – Saranya M Dec 03 '19 at 11:40
-
I think your best option will be: Show the Toast message from the onCreate method of application B's launcher activity and immediately close the application B programmatically, for example like this: https://stackoverflow.com/questions/6330200/how-to-quit-android-application-programmatically After closing the app, the toast message will still stay for a time. The downside will be that the user will see a white screen ( or a placeholder that you can put) for a second. – Gegham Kurghinyan Dec 04 '19 at 13:37