如何显示不同的内容,这取决于应用程序是否打开第一次? [英] How to display different content depending on whether the app is opened first time?

查看:98
本文介绍了如何显示不同的内容,这取决于应用程序是否打开第一次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示不同的内容取决于该应用是否被打开第一时间或使用者设定的东西?

How to display different content depending on whether the app is opened first time or the user setup something?

想象一下,一个活动A,B,如果用户打开应用程序第一次还是没有在活动B,然后显示b活动设置的东西,否则显示活性的。

Imagine a activity A, B, If the user open the app first time or haven't setup something in activity B, Then display activity B, otherwise display activity A.

如何克服呢?谢谢你。

推荐答案

如果你想显示不同的活动,如果用户打开应用程序第一次不同的活动第二次或第三次等等,那么你可以使用下面的方法。

If you want to show different activity if user opened the app first time and different activity second or third time and so on then you can use below approach.

您可以使用共享preference来实现这一点。

检查像这样的情况,在飞溅的活动:

Check the condition like this in the Splash Activity :

SharedPreferences preferences = getSharedPreferences("prefName", MODE_PRIVATE);
if(!preferences.getBoolean("isFirstRun", false)) {
    // This mean App Launch First Time
    SharedPreferences preferences = getSharedPreferences("prefName", MODE_PRIVATE);
    SharedPreferences.Editor edit= preferences.edit();

    edit.putBoolean("isFirstRun", true);
    edit.commit();
    // Open the B Activity
} else {
    // This mean App Launch Second or third ... time and start the A Activity
}

这篇关于如何显示不同的内容,这取决于应用程序是否打开第一次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆