在电话中两个发射活动,一个是关于平板电脑 [英] Two launcher activities on phone, one on tablet

查看:108
本文介绍了在电话中两个发射活动,一个是关于平板电脑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造为Android 4.0+的应用程序,我想实现这种行为。两个不同的活动将有两个发射器的图标,当用户的设备是一个电话,而这将是只有一个(活动将包括片段,我将显示为在一个主活动翼片)上平板设备。我知道,一个可以设置多个发射活动的清单,但我想,也许我需要的东西,将在运行时确定该操作(在Java code)。

解决方案
  

两个不同的活动,将有两个发射器图标,当用户的设备是手机,这将是只有一个(活动将包括片段,我将显示为一个主要活动标签)的平板电脑设备。

有一个在Android的手机和平板电脑的概念。我会假设你是手机,并在屏幕尺寸方面的平板电脑的区分。

如果这是真的:

步骤#1:创建一个 RES /价值/ bools.xml 文件,定义两个<布尔> 资源, is_phone is_tablet 。有 is_phone is_tablet

第2步:创建一个 RES /值-... / bools.xml 文件,其中 ... 是什么预选赛你与你的布局使用手机和平板电脑之间(例如, -large -xlarge -swNNNdp )。定义相同的两个<布尔> 具有相反值(资源也即, is_phone is_tablet )。

第三步:两个活动添加到您的清单,各自成立了 / LAUNCHER <意向滤光器> 。在要在手机使用的,请将安卓启用=@布尔/ is_phone<活性GT; 元素。在要在平板电脑使用的,添加安卓启用=@布尔/ is_tablet<活性GT; 元素。

这样,根据您正在使用的布局相同的规则,你将有一个不同的发射活动。


显然,这是不行的,但我发誓用。

另一种选择是有一个活动是 / LAUNCHER 之一。有它设置了安卓主题=@风格/ Theme.NoDisplay,因此它不具有用户界面。有它做出决定,在Java中,的onCreate(),其中你的真实的入口点的活动,是适合于给定的屏幕尺寸,可能使用相同的布尔资源我上面提到。拥有它,然后调用 startActivity()来控制传递给正确的活动的的通话完成()本身(这样用户就不会遇到在返回堆栈一种无形的活动)。这种技术也被用在情况下,有没有办法通过清单来控制这一点,比如我们有地图V1或不,你有机器人:要求=假<使用库> 元素

I am creating an application for Android 4.0+, and I want to achieve this behavior. Two different activities will have two launcher icons when the user's device is a phone, and it will be just one (the activities will consist of fragments that I will display as tabs in one main activity) on tablet devices. I know that one can set up multiple launcher activities in the manifest, but I think that maybe I would need something that will determine this operation during runtime (in java code).

解决方案

Two different activities will have two launcher icons when the user's device is a phone, and it will be just one (the activities will consist of fragments that I will display as tabs in one main activity) on tablet devices.

There is no concept in Android of "phone" and "tablet". I am going to assume that you are distinguishing between "phone" and "tablet" in terms of screen size.

If that is true:

Step #1: Create a res/values/bools.xml file and define two <bool> resources, is_phone and is_tablet. Have is_phone be true and is_tablet be false.

Step #2: Create a res/values-.../bools.xml file, where ... is whatever qualifier you are using with your layouts to distinguish between "phones" and "tablets" (e.g., -large, -xlarge, -swNNNdp). Define the same two <bool> resources there with opposite values (i.e., is_phone is false, is_tablet is true).

Step #3: Add both activities to your manifest, each set up for the MAIN/LAUNCHER <intent-filter>. On the one you want to use on a "phone", add android:enabled="@bool/is_phone" to the <activity> element. On the one you want to use on a "tablet", add android:enabled="@bool/is_tablet" to the <activity> element.

This way, based on the same rules that you are using for your layouts, you will have a different launcher activity.


Apparently, this doesn't work, though I swear it used to.

Another option is to have a single activity be the MAIN/LAUNCHER one. Have it set up with android:theme="@style/Theme.NoDisplay", so it does not have a UI. Have it make the determination, in Java, in onCreate(), which of your "real" entry-point activities is appropriate for the given screen size, perhaps using the same bool resources I cited above. Have it then call startActivity() to pass control to the right activity and call finish() on itself (so the user does not encounter an invisible activity on the BACK stack). This technique is also used in cases where there is no way to control this via the manifest, such as "do we have Maps V1 or not" where you have android:required="false" on the <uses-library> element.

这篇关于在电话中两个发射活动,一个是关于平板电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆