I’m trying to write correct intent filter.
I’m basically familiar with intents, they work fine in my app, but i want to know the better way to do it. Here’s what i need to do:
I have an application that owns some data. (data from ECU, engine control unit) There’s two Activities: one Activity can display data as a digits, and another can display it as a graphs.
Let’s see on the first activity.
- What does it do? It displays.
- What does it display? ECU data.
- How does it display this data? as a digits.
The second activity is almost the same, but third item is different: it displays data as a graphs.
So, I want to be able to send intent that specifies exatly all info, just like “Hey Android, I need to display ECU data as a digits“, and then first activity should be opened.
And I also want to be able to send intent that specifies only first two items, just like “Hey Android, I need to display ECU data“, and then android should ask user what activity should be opened.
My app also should be able to respond to other apps.
What’s the better way to achieve all this?
UPDATE: Here’s my xml. What should i specify in <intent-filter>?
<activity
android:name=".MyActivity"
>
<intent-filter >
<!-- what should i specify here? -->
</intent-filter>
</activity>
UPDATE 2: Here’s what i’m trying to do: I have an application with Service that communicates via bluetooth with remote device and receives ECU data. There’s some simple Activities that can display this data: as I already said, one can display digits, another can display graphs. This application provides AIDL interface for any another application to be able to get ECU data too.
As I said, these Activities is quite simple, they provides just basic user interface.
Say, one man wants this data to be displayed like moveable-pointer indicator. No problem: he can write his own Activity that will bind my Service, get data from it and display just how he wants.
Then, if i send Intent like “Hey Android, I need to display ECU data“, then Android should ask me what Activity should be opened, and I want to be able to see this new Activity too.
Well, i found myself what i looked for.
in AndroidManifest.xml:
And then i can say “Hey Android, I need to display car data” just like that:
If i want to say “Hey Android, I need to display car data as a digits“, i need to replace
CATEGORY_DEFAULTwith my own category:And that’s it. Of course, i can replace
DIGITSwithGRAPHSto openMyActivityForGraphsinstead ofMyActivityForDigits. It works just like i want it to work.