android:onNewIntent

本文详细介绍了Android中Activity的不同启动模式及其应用场景。重点讲解了singleTask模式下如何避免Activity重复实例化,以及不同启动模式下Activity生命周期方法的调用顺序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文编写目的:供自己查阅

1、通过Intent启到一个Activity的时候,就算已经存在一个相同的正在运行的Activity,系统也会创建一个新的Activity实例。为了不让Activity实例化多次,我们需要通过在AndroidManifest.xml配置启动方式。

2、launchMode为singleTask的时候,通过Intent跳到一个Activity,如果系统已经存在一个实例,系统就会将请求发送到这个实例上,但这个时候———-系统就不会再调用onCreate方法,而是调用onNewIntent方法。

3、但是为了以防万一,最好在onCreat方法里也写上操作,因为后台运行的Activity可能在内存过高时被系统杀掉,这时就会走onCreat方法

4、其他应用发Intent,执行下列方法:onCreate,onStart,onResume。
如果Activity处于任务栈的顶端,也就是说之前打开过的Activity,现在处于onPause,onStop 状态的话,其他应用再发 送Intent的话,执行顺序为:onNewIntent,onRestart,onStart,onResume。

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:installLocation="preferExternal"> <supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" /> <uses-permission android:name="android.permission.NFC" /> <uses-feature android:name="android.hardware.nfc.hce" android:required="false" /> <uses-feature android:name="android.hardware.nfc" android:required="false" /> <application android:theme="@style/UnityThemeSelector" android:icon="@drawable/app_icon" android:label="@string/app_name" android:hardwareAccelerated="true"> <activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <!-- 添加NFC处理 --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="myapp" /> </intent-filter> <!-- 添加深度链接处理 --> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:scheme="xl" android:host="goods" android:port="8888" android:pathPrefix="/goodsDetail" /> </intent-filter> </activity> </application> </manifest> 这是我现在的xml文件,我的应用包名为com.example.text 我该怎么更改,并使用什么URL去启动应用并传递数据
最新发布
08-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值