I have an Activity and assume that has been launched. When the other application use startActivity method to start my Activity, my Activity will show and run the onResume Method, but I can't find any way to get the intent which is used in startActivity method by the other application. I want to get the extra data in the intent. How can I do?
EDIT
My Activity is singleTask, and I want to get the startActivity intents form other applications. I think it is not associate with filters.
Have you tried using getIntent() ?
Then you can do:
this.getIntent().getExtras();
After that if you need new intents just override the onNewIntent function in your activity.
I simply say an example. When we need to share something. We click share button which shows a list of app by which we can share our things.
So, if you want to make that kind of app which can receive other app data then you need make your activity capable of receiving that data. In order to receive implicit intents, you must include the CATEGORY_DEFAULT category in the intent filter in manifest.
Below this link you will get some more information : http://developer.android.com/training/basics/intents/filters.html
Related
Everyone knows if you create intent to start another activity, you pass in as a parameter into startActivity. But I just thought about the possible scenario: intent says system "call this activity", the system sees manifest and then runs activity, or this running acts internally in the app, something like "call some method of some class"?
Probably a stupid question, but I couldn't find enough info. So how does it works?
Following is the way how intent communication works:
Activity A creates an Intent with an action description and passes it to startActivity().
The Android System searches all apps for an intent filter that matches the intent. When a match is found,
the system starts the matching activity (Activity B) by invoking its onCreate() method and passing it the Intent.!
I fell confused about the relationship between the Activity, Action and Intent?
And also an another question about the Implicit intents : for example I want to start this action ACTION_CALL to make a phone call,obviously, this is an Implicit intent, so I should write like this Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
But I should also need to set the data. Here is my question : How can I know what's the uri looks like? What's the schema?Please just don't tell the simple answer.How do you know that? Is there any API I should look for? And I know in the manifest <data android:scheme="xxxxx"/> So where is the manifest about the action or activity Intent.ACTION_CALL? I can't find it.
Activity - It says, from where to where you want to send message e.g: from Activity A to Activity B.
Action - It says, what this message means e.g: Open a URL in webview or make a call etc.
Intent - It says, how to transfer the message and other extra information e.g: directly through explicit intent or indirectly by selecting from multiple options through implicit intent.
I am creating my own app and at one point I want that user can go to any other application.So what will be the best code for that?
You can do that in many ways, but one of the common method is intents. You can create implicit intents for this purpose.
here is a sample code :
//From MainActivity.onCreate()
Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://google.com"));
startActivity(intent);`
you can find further details about intents here.
I am trying to connect to different activities from a custom soft keyboard. I need the activity underneath the keyboard to allow data to be sent without the activity creating a new instance of itself. For example: if the keyboard is over the messaging application, I want to send that application data without losing the current conversation that the user is typing into. I currently have the following code to send data to the activity.
Intent sendIntent = new Intent(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
//sendIntent.putExtra("thread_id", (long) 1);
sendIntent.setType("image/*");
startActivity(sendIntent);
I am getting the following obvious error when I try to run it...
E/AndroidRuntime(6129): android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
How can I keep the current activity underneath the keyboard from resetting itself when an intent is sent from the keyboard service? Or more simply, how can I send an intent from a service without setting the FLAG_ACTIVITY_NEW_TASK flag?
You can't really do this like that. A Service can't pass data to an Activity without "starting it". You don't want to do that. You want to pass data to an "already started" Activity. There's 2 ways to do this:
Use a bound Service. Have the Activity bind to the Service. The Activity can then call methods on theService (using AIDL) and receive returned data.
Use a BroadcastReceiver. Have the Activity create and register a BroadcastReceiver to listen for the returned data. In your Service, send a broadcast Intent when you want to transmit data to the Activity.
You can do this by several ways but you must set flag in order to complete task.
If you want to create a new instance and close the current instance you need to set Intent.FLAG_ACTIVITY_CLEAR_TOP.
If you want to reuse the same instance of the activity in this case you need to set both Intent.FLAG_ACTIVITY_CLEAR_TOP and Intent.FLAG_ACTIVITY_SINGLE_TOPafter that it will not create another instance of the activity but call onNewIntent() of activity to run the new Intent.
This question already has answers here:
What is an Intent in Android?
(14 answers)
Closed 8 years ago.
I dont know much about intent (or android) so.. Can someone please explain me what is it exactly? i have search on the internet, A LOT.
Also what does each line of this code do?
Intent intent = new Intent (this, DisplayMessageActivity.class);
intent.putExtra("a", "b");
Thanks in advance
I suggest reading Android Intents
You couldn't have search for very long, since this is very basic topic.
I suggest you read more of Android's API guides.
Line 1 = Create message that describes what to do, in this case start "DisplayMessagActivity"
Line 2 = Add content to the message
Intent intent = new Intent (this, DisplayMessageActivity.class);
For this line, its function is to create a navigation from the current activity/page to the displaymessageactivity page.
it is like from here to there.
For this intent.putExtra("a", "b"); the purpose of this is to put like a temp storage/variable to pass to the next page for retrieval. In this case, you put the value "b" in the variable "a". With this method, you can use the value on the other activity or page.
All the above are just storing of info, it is not executed yet. if you want to execute the intent do the following
startActivity(intent);
The best example to state the behavior of Intent is it behaves like a POSTMAN that delivers message to the stated address.
Whether it may be calling service ,BroadCastRecivers ,Activity they are used in number of occassion.
Intents are asynchronous messages which allow application components
to request functionality from other Android components. Intents allow
you to interact with components from the same applications as well as
with components contributed by other applications. For example, an
activity can start an external activity for taking a picture.
Intents are objects of the android.content.Intent type. Your code can
send them to the Android system defining the components you are
targeting. For example, via the startActivity() method you can define
that the intent should be used to start an activity.
An intent can contain data via a Bundle. This data can be used by the
receiving component.
Intents can be used to start Service, call Activty, call Sub Activity, transfer the data between Activity or retrieve the data from Activity