android:launchMode="singleTask"和 onNewIntent(Intent intent)两个特性,现总结一下经验:

android:launchMode="singleTask" 配置在 Mainifest 中,它保证了栈中此Activity总是只有一个,无论你启动它多少次;

onNewIntent(Intent intent) 是Override Activity的父类方法,只有仅在点Home键退出Activity而再次启动新的Intent进来才被调用到;

它们两结合使用,可以做到监听home键(仅当发起新的Intent)。

代码如下:

Manifest.xml

<activityandroid:name=".OnNewIntentDemo"android:launchMode="singleTask"                  android:label="@string/app_name">            <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>            <intent-filter> <action android:name="android.intent.action.VIEW" />  <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="video/*" /></intent-filter></activity>

Activity 中

@Overrideprotected void onNewIntent(Intent intent){     if(DEBUG) Log.i(TAG, "onNewIntent ~~~~~~~ intent = "+intent);     super.onNewIntent(intent);}


更多相关文章

  1. Android 1.6 关于SD卡的新特性
  2. android kitkat(4.4以上)各个版本的特性解析
  3. android开发笔记之2012版辅助开发工具包(ADT)新功能特性介绍及安装
  4. 有关Material Design新特性的详解。
  5. 我使用过的 控件的一些特性(layout_weight,paddingleft)
  6. android 5.0新特性
  7. Android M5 新特性
  8. 2012版辅助开发工具包(ADT)新功能特性介绍及安装使用
  9. android和ios的系统特性区别

随机推荐

  1. RelativeLayout用到的一些重要的属性
  2. Android布局的一些属性值
  3. Android布局属性大全
  4. Android控件笔记——CheckBox复选框
  5. Android(安卓)Manifest merger failed :to
  6. android selector 中的几个关键状态
  7. android添加动画效果
  8. Android开发神贴整理
  9. Android(安卓)ZoomControls的使用
  10. Android布局的一些属性值