如果用户在第一次打开注册或登录Activity时打开它,则创建android初始信息页面

时间:2015-12-12 10:59:09

标签: android splash-screen

我是Android新手,尝试创建一个以启动画面打开的应用程序,然后显示3-4个初始应用程序信息活动/片段,在最后一个Activity /片段中应该有一个注册按钮或文本。然后应显示另一个闪屏,用户应直接进入注册页面。

您能否向我推荐任何与我的要求类似的链接或教程?

对于AndroidManifest.xml中的启动画面我把它放入启动器并且它工作正常,在启动画面后打开MainActivity,使用FragmentPagerAdapter创建3个可转换的信息片段。

MainActivity.xml

<activity android:name=".SplashScreen" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
<activity
    android:name=".MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.default" />
    </intent-filter>
</activity>

myPageAdapter.java

public class ma_pager_adapter extends FragmentPagerAdapter {
    public ma_pager_adapter(FragmentManager fm) {
        super(fm);
    }


    @Override
    public Fragment getItem(int i) {

        switch (i) {
            case 0:
                tab1 t1 = new tab1();
                return t1;
            case 1:
                tab2 t2 = new tab2();
                return t2;
            case 2:
                tab3 t3 = new tab3();
                return t3;

        }
        return null;
    }

    @Override
    public int getCount() {
        return 3;
    }//set the number of tabs

下面显示了其中一个fragement以及我正在尝试打开新活动的代码,但它无效。基本上我没有从这个Fragement中打开一个新的活动。

Tab3.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="#117edd">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="GET STARTED"
        android:id="@+id/goToSignUPPage"
        android:layout_gravity="bottom"
        android:background="#f46821"
        android:gravity="center"
        android:textColor="#ffffff"
        android:onClick="clickToOpenSignUpPage" />

</LinearLayout>

Tab3.java

public class tab3 extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view =inflater.inflate(R.layout.tab3,container,false);
        return view;
    }

    public void clickToOpenSignUpPage(View view) {
        System.out.print("HERE");

        if(view.getId()==R.id.goToSignUPPage){
            /*Intent i = new Intent(tab3.this,SignUpPage.class);*/
            Intent i = new Intent(getActivity(),SignUpPage.class);
            getActivity().startActivity(i);
//            startActivity(i);
        }
    }

3 个答案:

答案 0 :(得分:0)

一旦经过该页面,您就可以对此.Change值使用共享优先级,因此它只会打开一次,请参阅此Shared preferences

答案 1 :(得分:0)

我为此做的是使用共享首选项。

将此添加到您的主要活动:

if (bool == false){
//open the page you want
}

它的作用是查看保存名称是否已保存,如果它不存在则返回valse

所以你现在可以做的是:

SharedPreferences settings = getSharedPreferences("APPNAME", 0);
//makes it editable
SharedPreferences.Editor editor = settings.edit();
//puts the bool on true
editor.putBoolean("SAME SAVE NAME", true);
//saves it
editor.commit();

为了使bool成立,你可以这样做:

Makefile

可以在此处找到更多信息:http://developer.android.com/reference/android/content/SharedPreferences.html

答案 2 :(得分:0)

试试这个

private SharedPreferences prefs;
private static final String IS_FIRST_TIME = "is_first_time";

prefs = PreferenceManager.getDefaultSharedPreferences(this);

if (prefs.getBoolean(IS_FIRST_TIME, true)) {
    Toast.makeText(getApplicationContext(), "First time", Toast.LENGTH_SHORT).show();
    prefs.edit().putBoolean(IS_FIRST_TIME, false).commit();
} else {
    Toast.makeText(getApplicationContext(), "Not first time", Toast.LENGTH_SHORT).show();
}

您可以使用API​​级别9&#39;中添加的&#39; apply()而不是在API Level 1&#39;

中添加&#39; commit()