Fragment and Intent Filters

We all know how we can use intent filters in our AndroidManifest.xml to declare the capabilities of actions such as search, push, etc. I am currently using such an intent filter to register a custom URL scheme as follows:

<activity android:name="NameOfActivity" > <intent-filter > <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWABLE" /> <data android:host="" android:scheme="customscheme" /> </intent-filter> </activity> 

All this worked very well, until I decided to convert all my actions into fragments, since I needed to display the user interface differently on the tables. Now, on devices declared as large or large, instead of switching between actions, I have one action that removes and adds new fragments on request. This choice was made, since the left side of the screen always displays the same content, so instead of adding this content and all the actions, I change the fragments instead.

The problem is that while the intent filter starts the correct operation on the phone, this activity should never be launched on the tablet. Instead, I would like to handle this URL in the fragment. At the moment, I see no way to fix this. One thought was to programmatically add an intent filter, but after some research, I can't figure out if this is possible or not. Another thought was to somehow add an intent filter to the fragment, but that would not work, since the fragment cannot be launched without the activity hosting it.

In short : On the phone, I need one action to process the intent filter, but on the tablet I need another action to process the intent filter.

Is there any way to do this?

+4
source share
3 answers

In a month, I still have to find a solution. As far as we know, activity starts on top of everything else. This breaks the whole thread, and this is a pretty bad workaround, but at least it works. Excluding this function, there was nothing, and this is the only solution. I would be very happy to see a better solution to this, but as you know, it seems that this is simply impossible.

+1
source

Wouldn't it be possible for your intent-filter action to determine the resolution of the device, and then start the corresponding operation for this?

In addition, I thought that Fragments were designed according to your case: describe the aspects of the user interface, and then, depending on the screen resolution, show either all or some of these functions.

http://developer.android.com/guide/topics/fundamentals/fragments.html

+1
source

I think you are approaching the whole paradigm of fragments in the wrong direction.

On the phone, I need one action to process the intent filter, but on the tablet I need another action to process the intent filter.

To rephrase your resume in this way, I would come closer to the situation:

On the phone, I need an operation to download a specific fragment based on the device’s screen. Here, the fragment downloaded on the phone must have some mechanism to trigger another action containing additional information.

On the tablet, I need an operation to load two fragments. Here, the left fragment will always display the same content, and the right fragment will change with some mechanism to replace the fragments.

Different fragments can be specified in the XML layout (for one action, using a different XML layout file in different layout folders - using size determinants), so there is no need for Java to load another fragment / set of fragments based on the size of the device.

It is difficult to work further without understanding your application, and why you selected (or why you need) individual actions.

If you want to continue your current solution, you can manually override the backup using startup modes .

0
source

Source: https://habr.com/ru/post/1381509/


All Articles