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.
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.
Related
The problem is only when my activity already shown it begins updates and it look no good. How it works: in onStart of activity I send cmd to service to get update data, also I register brodcast listener there. I want to prepare received data from service to show before activity appears. How to do that? Thanks.
How it works now: when I back from another activity first I see old data and then it changes (very fast but you can see it) to new.
if you want to setup things before your activity is shown you need to do things in the onCreate method instead of onStart method.
further informations in android documentation
When you send the command to the service to update your data, you should change the views in your Activity to show loading indicators, or a blank view, or whatever you want the user to see until the Broadcast comes in that your new data is ready. Then you shouldn't need to worry about old data being visible.
I need your help because I want to write an Android app which works like this: when I tap the app launcher, I show an activity in which the user has to insert some data, like his name ecc. These data are passed to a background service through an intent and when the service starts I show a notification. When I click on the notification I show another activity in which the user can press a button to stop the service. Everything works fine but I would like that, if I tap again the app launcher but the service is active, the user didn't see the first activity (the one in which he has to insert the data), but the last one in which there is the button to press to stop the service. I don't have a clue of how to do. Can you help me please? Thanks.
Do you really need two Activities for these use cases? You can have just one Activity and two Fragments, one for starting the Service, and one for stopping. In your Activity's onCreate() method check if the Service is running and inflate the right Fragment dynamically.
I have an application wherein when the user first open's the application he is asked to login with his credentials. So this activity say "Register" is the default activity. But once the user has logged in I want the default activity to change to some other activity say "MainActivity" from there on.
So how can i achieve this programatically?
I know one approach is to create a blank activity and based on a flag to launch the desired activity. Is there any other approach other than this ? And is the previous approach efficient ?
Thanks in advance :)
it is efficient, how ever you dont have to create a new blank activitiy, rather just use your mainActivity and if the user is not registered spawn off the Register activity cause that activity is only going to happen once. and the normal usecase is to stay in main activity.
that is how most people do it:) hope this helps
I'm developing an app that downloads some data in service and show it via push-notifications, also user can read other data in activity. So could you explain me how can i make a dilalog that's show's to user when WIFI/3G is turned off and says something like this "For normally app working you should turn 3G/WIFI on". A problem is that i must implemet it by service callback, i.e. by this logic:
service start downloading data --> No internet --> Cheks if WiFi/3G is turned off --> Shows in any Activity a Dialog.
I know that i can make it by using a receiver, but how a can call a dialog in every activity? Or i don't need an activity, just a context in OnReceive method, right? Please give me any ideas.
Or i don't need an activity, just a context in OnReceive method, right?
No, that is incorrect. A Dialog needs an Activity. You could show a Toast from onReceive() using the Context that it has.
Or, as Junior was suggesting, you can create an Activity with a Dialog theme. To do this, you simply need to add the following line to the <activity> tag in your manifest.xml for the appropriate Activity
android:theme="#android:style/Theme.Dialog"
This is nice because it gives you all the functionality of an Activity while displaying as a Dialog so the user doesn't feel like they have "left" where they are.
Launch an activity (of your own) with a dialog theme.
Hope it helps!
I have implemented a search-function in my sourcecode which will be started when the user clicks the search-button on his device or the one in my actionbar. If he clicks the one on my actionbar I simply call onSearchRequested. Now here is my problem:
When the Search is done I display the results in a ListView. If the user clicks on an Item I want do go back to my MainActivity (which will always exist when the app isn't finished) and modify some values there und call a method of Main.
I know that there is startActivityForResult but I don't know how I could implement that because if the User hits the search button of his device the app automatically calls onSearchRequested... So the only solution that comes to my mind would be to implement a static method in my Main-Activity which I can call from within the Activity displaying my search results. But that isn't such a nice solution (or?)!
To summarize my question: is there an elegant way to get back from my activity displaying my search results to my main-activity and transfer data without startActivityForResult or implementing a static method in Main?
Thank u very much!
Implementing startActivityForResult is pretty easy. This might help you.