5

We all know how we can use intent-filters in our AndroidManifest.xml to declare capabilities of activities such as search, push, and so on. I currently use such an intent-filter to register a custom URL scheme in the following manner:

<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>

This all worked very well until I decided to transform all my activities into fragments, as I needed to display the user interface in a different manner on tables. Now, on devices that are declared as large or greater, instead of switching between activities I have one activity that removes and adds new fragments as requested. This choice was taken as the left-hand side of the screen allways displays the same content, so instead of adding this content ito all activities I instead change the fragments.

The problem here is that while the intent-filter launches the correct activity on the phone, this activity should never be launched on a tablet. Instead, I would like to handle this URL in the fragment. As of now, I see no way of fixing this. One thought was to add the intent-filter programmatically, but after some research i cannot figure out if this is possible or not. Another thought was to somehow add the intent-filter on the fragment, but this would not work as a fragment cannot launch without an activity hosting it.

In short: On a phone, I need one activity to handle the intent-filter, but on a tablet I need another activity to handle the intent-filter.

Is there any way of accomplishing this?

Bendik
  • 928
  • 11
  • 23
  • Good solution: http://stackoverflow.com/questions/13202805/how-to-specify-activities-that-are-only-for-phones-or-tablets-on-android/13202806#13202806 – alcsan Feb 17 '13 at 19:23

3 Answers3

1

Wouldn't it be possible to have your intent-filter activity determine the resolution of the device, then start the appropriate activity for that?

Also, I thought Fragments were designed with your case in mind: describe aspects of the user interface and then depending on screen resolution show either all or some of that functionality.

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

skynet
  • 9,898
  • 5
  • 43
  • 52
  • I cannot see how this would solve my problem. It would work in the case where the app is running on a phone, as the right activity has been started. But on a tablet, how would the activity push the fragment in the other activity? It does not have a reference to it, and relaunching the other activity is not an alternative as that would render my system useless. – Bendik Nov 17 '11 at 10:52
1

After one month, I have yet to find a solution to this. As of know, the activity is launched on top of everything else. It breaks the whole flow, and is a quite bad workaround, but at least it works. Excluding the feature was a no-go, and thus this was the only solution. I would be really happy to see a better solution to this, but as of know it seems that it simply is not possible.

Bendik
  • 928
  • 11
  • 23
0

I think you're approaching the whole Fragment paradigm in the wrong direction.

On a phone, I need one activity to handle the intent-filter, but on a tablet I need another activity to handle the intent-filter.

To rephrase your summary in the way I would approach the situation:

On a phone, I need the activity to load a particular fragment, based on device screensize. Here, the fragment loaded on the phone would have some mechanism to launch another activity containing more information.

On a tablet, I need the activity to load two fragments. Here, the left fragment would always display the same content, and the right fragment loaded would change with some mechanism to swap fragments.

The different fragments can be specified in the layout XML (for the single activity, using a different XML layout file in different layout folders - using the size qualifiers) so there's no Java required to load a different fragment/set of fragments based on device size.

It's difficult to elaborate further without understanding your application, and why you've chosen (or why you need) to have separate activities.

If you'd like to continue with your current solution, you can manually override the backstack, by using launch modes.

ataulm
  • 15,195
  • 7
  • 50
  • 92