java-仅在从启动器启动应用程序时显示启动屏幕
作者:互联网
我有这样的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