I've successfully being able to use the ACTION_SEND intent which displays my application in the list when the share button is pressed in the gallery. My app basically sends the selected picture to my computer and no further input form the user is required. Rather than starting my app when selected in the list which is an unnecessary step is it possible to pass the data to my own service which sends the picture and avoid starting my app?
If not what other options do I have? Start my app, sent the picture and close the activity?
Rather than starting my app when selected in the list which is an unnecessary step is it possible to pass the data to my own service which sends the picture and avoid starting my app?
ACTION_SEND is used for starting activities, not services -- sorry.
If not what other options do I have? Start my app, sent the picture and close the activity?
Sounds reasonable. If you do all of that in onCreate(), call finish(), and never call setContentView(), nothing will be shown to the user.
Related
I have a bug in my app which I thought I knew how to resolve, but now I've thought more about what is happening I'm not sure I do know the fix.
My app receives an incoming intent from a calling third party app as a string. That string can be sent as a SEND intent or a VIEW intent.
All of that works fine unless the app is already running...
This is what is happening:
My app is not running (not listed in the running apps view)
Share is clicked in another (third party) app and my app is selected to receive the shared text (text1).
My app opens and the text is displayed (and processed) as expected.
The user switches back to the third party app and shares some different text (text2) and my app is selected to receive this new text.
My app opens, but the original text (text1) is still displayed.
At this point I thought that the bug was because I am reading the intent in onCreate() and then displaying and processing it. My thinking was that as the app is already running onCreate() is not being called when the app is shown the second time as we jump into the lifecycle at onResume().
However, if I continue the test as follows:
Without exiting my app the user switches back to the third party app again and again shares the same piece of second text (text2) with my app.
My app is displayed again but this time correctly shows and processes the second text.
How can this be, as the app is still running, surely onCreate() is still not going to be called!
I thought that the fix was going to be simply to move the getIntent() call into onResume() (or onStart() ?) But now I'm not sure about this. Is this right thing to do?
The core of the issue is the fact that your Activity is already on top of the activity stack when the second Intent is being fired.
The launch mode will matter here.
What you can do is, set the launchMode to singleTop, and then get the intent in onNewIntent() method.
That is a good way of handling such scenarios. Please read the link above and it will make things very clear.
I am using GCM to send push notifications to my Android application and when the user clicks the notification, they should be taken to a specified view in the application (For context: It's an event log).
I understand that in the simplest case, I just add some parameters to the intent that is starting the app.
However, my app requires some remote data to be available when entering my MainActivity. When starting the application normally, it's pointing to another activity, let's call it AppStartActivity. It's showing a Splash screen while downloading the neccessary data and launches MainActivity when it's ready.
When starting the app from a notification, the neccessary data may or may not be ready, depending on whether the app is currently in background (and if it has not been garbage collected). Therefore, I think I have to launch AppStartActivity when clicking the notification, and then somehow forward the Intent parameters and I'm not sure it's the right way. I have formulated some questions about this:
Is it correct to lauch AppStartActivity with the parameters I will need in MainActivity later and then just forward them when switching to MainActivity?
Is there a simpler way to do this, such as finding out the state of the application when clicking the notification and then choose either AppStartActivity or MainActivity depending on if the neccessary data is available? The reason I'm asking is that when I create the notification, the data may or may not be available, but it may change during the time passing before the user to interact with the notification. I understand that I can launch a new activity that is just checking the state and then launch either MainActivity or AppStartAcitivty, but it seems like it could be a bit too complicated...
I'm thankful for any input on this matter. Please let me know if I have left out some details.
as I understand it, I had a similar situation, and this was my solution:
when I receive the GCM, my onReceive method starts a service
for getting the remote datas. Only when these datas are
avaiable in a local content provider, I throw the notification to the user.
[edit]
You have to manage any network error with some notice, otherwise you may lose the GCM notification
I launch another app from my application.
Is there any way to trigger my app when launched app closed?!
Is it good idea to use timer and check package name ?!
Starting another activity doesn't have to be one-way. You can also start another activity and receive a result back. To receive a result, call startActivityForResult() (instead of startActivity()).
For example, your app can start a camera app and receive the captured photo as a result. Or, you might start the People app in order for the user to select a contact and you'll receive the contact details as a result.
Of course, the activity that responds must be designed to return a result. When it does, it sends the result as another Intent object. Your activity receives it in the onActivityResult() callback.
More info here.
If you launch the app with startActivityForResult, you will end up in onActivityResult in your application when it closes, that is the normal flow.
But if you want to always launch your app when the other closes, it can be done using a service, but I wouldn't recommend doing that since it's bad practise.
in the first activity of my app i have created some fields as like a registration form and then it goes on to the other activities. Once the user starts the app he must fill all those fields.
when the user closes the app and open's once again, now i should not diplay the registration activity. This must be done until the app is deleted from that device.
I came to know that in iPhone they have an inbuilt option called as User Default, how to create such a thing in ANDROID apps.
What is it called in android, pls explain me....if possible with a sample code or example
What is it called in android
It is called "an if statement".
Your activities, in onResume(), can check if the user has registered by checking your database (or wherever you are storing the data). Then, if the user has not registered, those activities can call startActivity() to launch the registration activity.
is it possible to press a button and start a call e.x. in skype?(i know that is possible for a telephone call but i would like to see if i can make this stuff with a voip app as skype)
If the user has skype installed, and the user tries to place a call there are two options you can take:
i.e. just try and call skype directly (but this requires knowing the correct intent to launch skype) or you request to make a call and the user will be shown the option to use skype to place the call (unless they've set the default dialer and the primary application).
I think there may be a way to get a list of activities that are registered to handle certain events (i.e. get the list of dialler apps on the device) from this you might be able to find the skype app and get enough information to force the use of that. The problem with this is you are then tied into using skype and only skype rather than let the platform handle it.