java-仅在从启动器启动应用程序时显示启动屏幕
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-仅在从启动器启动应用程序时显示启动屏幕,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3221字,纯文字阅读大概需要5分钟。
内容图文
![java-仅在从启动器启动应用程序时显示启动屏幕](/upload/InfoBanner/zyjiaocheng/686/1cdb6e79de414cdca0fc04f5e96bcf8d.jpg)
我有这样的SplashActivity:
public class SplashActivity extends Activity {
Handler Handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Handler = new Handler();
Handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
}, 1500);
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
}
}
其在AndroidManifext.xml中的声明如下:
<activity
android:name=".SplashActivity"
android:theme="@style/Splash"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts"/>
<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:host="brokenhearts.ml"
android:scheme="http"
android:pathPattern="/*"/>
</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:host="brokenhearts.ml"
android:scheme="https"
android:pathPattern="/*"/>
</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:host="www.brokenhearts.ml"
android:scheme="http"
android:pathPattern="/*"/>
</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:host="www.brokenhearts.ml"
android:scheme="https"
android:pathPattern="/*"/>
</intent-filter>
</activity>
我在我的应用程序中使用WebViews.问题是,每当用户在我的应用程序的其他活动中点击我的网站的链接时,都会从SplashActivity重新开始.这在某种程度上是正确的,因为那是我添加意图的地方.但是,我想知道此设置是否还有其他方法仅在从启动器或从URL意图启动(当应用程序未运行时)而不是从URL意图启动时显示启动屏幕.当应用程序已经在前台运行时触发.
如果无法通过这种设置进行操作,我还有什么其他方法可以解决?
解决方法:
检查appLinkData是否为null,然后显示SplashScreen,否则启动MainScreen
public class SplashActivity extends Activity
{
Handler Handler;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData;
if(appLinkAction!=null)
appLinkData = appLinkIntent.getData();
if(appLinkData!=null)
{
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
finish();
return;
}else
{
Handler = new Handler();
Handler.postDelayed(new Runnable()
{
@Override
public void run()
{
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
},
1500);
}
}
}
内容总结
以上是互联网集市为您收集整理的java-仅在从启动器启动应用程序时显示启动屏幕全部内容,希望文章能够帮你解决java-仅在从启动器启动应用程序时显示启动屏幕所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。