Android: not single entry point

Android应用组件化解析
本文探讨了Android应用程序如何通过组件化实现资源共享,特别是在不需要整个应用加载的情况下调用特定组件的功能。文章解答了关于如何仅启动目标组件而非整个应用的问题,并讨论了这种方式如何有助于节省手机资源。

        .....you can call upon that scroller to do the work, rather than develop your own. Your application doesn't incorporate the code of the other application or link to it. Rather, it simply starts up that piece of the other application when the need arises.

        For this to work, the system must be able to start an application process when any part of it is needed, and instantiate the Java objects for that part. Therefore, unlike applications on most other systems, Android applications don't have a single entry point for everything in the application (no main() function, for example).

 

    上面这段话是android dev guide文档中的一段,具体url是:http://androidappdocs.appspot.com/guide/topics/fundamentals.html

 

    关于这段有如下几个疑问:

                   1, 关于“ For this to work”中this的理解。 结合上文,我们知道,“this”是指“ it simply starts up that piece of the other application when the need arises”。 也就是说, appR为了用到appA中的scroller, android就只start appA中的scroller了?

 

                   2, 顺着问题1, 往下看,看到“the system must be able to start an application process when any part of it is needed”。 这里的“an application process”并不是“an application”, 也就是说为了appA中的scroller,系统启动一个进程,而这个进行中只有关于scroller的信息, 而不是把整个appA都启动。 这种情况下(进程中只有scroller的信息,而没有启动整个appA), 用户再启动appA,系统再怎么处理scroller?appA跟appR共用一个croller存储空间,这好像不大现实。 操作系统是怎么处理这个问题的?

 

                   3, 这样不只是有一个entry point的设计,是怎么来节省手机资源的?

`android:singleLine` 是 Android 中用于控制文本显示方式的属性,主要用于 `TextView` 等文本控件。 ### 作用 该属性用于指定文本是否单行显示。当设置为 `true` 时,文本会被强制显示在一行上,即使文本内容超出了控件的宽度也不会换行;当设置为 `false` 时,文本会根据内容和控件的宽度进行自动换行显示。 ### 使用方法 在 XML 布局文件中,可以直接为 `TextView` 控件添加 `android:singleLine` 属性来设置文本的单行显示模式。示例代码如下: ```xml <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:singleLine="true" android:text="这是一段很长的文本,将以单行显示。" /> ``` 在 Java 代码中,可以使用 `setSingleLine()` 方法来动态设置 `singleLine` 属性。示例代码如下: ```java import android.os.Bundle; import android.widget.TextView; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = findViewById(R.id.textView); textView.setSingleLine(true); } } ``` ### 注意事项 - **兼容性问题**:从 Android 4.0(API 级别 14)开始,`android:singleLine` 被标记为过时,推荐使用 `android:maxLines="1"` 来替代。虽然 `android:singleLine` 仍然可以使用,但为了保证代码的兼容性和可维护性,建议使用 `android:maxLines` 属性。示例代码如下: ```xml <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:maxLines="1" android:text="这是一段很长的文本,将以单行显示。" /> ``` - **与其他属性的配合**:`android:singleLine` 通常会与 `android:ellipsize` 属性一起使用,用于处理文本超出控件宽度时的显示方式。例如,设置 `android:ellipsize="end"` 可以在文本末尾显示省略号。示例代码如下: ```xml <TextView android:layout_width="100dp" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="end" android:text="这是一段很长的文本,将以单行显示并在末尾显示省略号。" /> ``` ### 跑马灯效果中的应用 在实现跑马灯效果时,`android:singleLine` 是一个必要的属性。跑马灯效果要求文本单行显示,并且需要设置 `android:ellipsize="marquee"`、`android:focusable="true"` 和 `android:focusableInTouchMode="true"` 等属性。示例代码如下: ```xml <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:text="这是一段很长的文本,将以跑马灯效果显示。" /> ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值