ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java-仅在从启动器启动应用程序时显示启动屏幕

2019-10-25 03:34:13  阅读:170  来源: 互联网

标签:splash-screen xml java android


我有这样的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);

       }
    }
}

标签:splash-screen,xml,java,android
来源: https://codeday.me/bug/20191025/1925777.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有