[英]onBackPressed() from deep link exit the app
I just start with Android with Java and I set Deep link when I open it from closed app I didn't see the splash screen and when I hit back button its exit the app how can I make it if its from deep link launch of the app to show splash screen and more important when I press back arrow to lead to Home screen keep in mind that activity is also accessible form another fragments so its need to be explicit from deep link to Home activity Here is my XML file:我刚从 Android 和 Java 开始,当我从关闭的应用程序打开它时我设置了深层链接应用程序显示启动屏幕,更重要的是,当我按返回箭头指向主屏幕时,请记住,活动也可以从另一个片段访问,因此它需要从深层链接到主活动的显式链接这是我的 XML 文件:
<application
android:hardwareAccelerated="true"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FoodRecipeAppProject"
tools:targetApi="31">
<activity
android:name=".SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RecepieActivity"
android:exported="true">
<intent-filter android:label="url">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="www.example.com"
android:pathPrefix="/recipe" />
</intent-filter>
</activity>
<activity
android:windowSoftInputMode="stateAlwaysHidden|adjustPan"
android:name=".DashBoardActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="false">
</activity>
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
</application>
You have to declare parentActivityname
on your manifest like this您必须像这样在清单上声明
parentActivityname
<activity
android:name=".RecepieActivity"
android:parentActivityName=".YourParentActivity"
android:exported="true">
<intent-filter android:label="url">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="www.example.com"
android:pathPrefix="/recipe" />
</intent-filter>
</activity>
and then override onBackPressed
function in your activity class like this然后像这样在您的活动 class 中覆盖
onBackPressed
function
@Override
public void onBackPressed(){
NavUtils.navigateUpFromSameTask(this);
}
This will make you back to parent activity when back button is pressed当按下后退按钮时,这将使您回到父活动
Instead of using an activity just to show splash screen, use SplashScreen API directly in the activity that is being deep linked.不要使用仅显示初始屏幕的活动,而是直接在深度链接的活动中使用SplashScreen API 。 Alternatively, you can also setup a routing activity which will handle all incoming deep link requests and show splash screen, after which it'll redirect to the activity defined in deep link.
或者,您还可以设置一个路由活动,它将处理所有传入的深度链接请求并显示启动屏幕,之后它将重定向到深度链接中定义的活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.