首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用户注册后如何停止显示教程/演练屏幕?

用户注册后如何停止显示教程/演练屏幕?
EN

Stack Overflow用户
提问于 2015-09-03 06:33:39
回答 1查看 212关注 0票数 0

我正在开发一个用户必须注册的应用程序。

我只在用户第一次安装和启动应用程序时显示演练/教程屏幕。

我希望一旦用户注册了,演练/教程就应该停止显示,但是在第一次不管用户是否注册之后,它们就会停止显示。

如何编写代码,以便只有在用户注册后才能停止显示演练/教程。

下面是我的Walkthroughs.java文件的代码:

代码语言:javascript
复制
public class Walkthroughs extends AppCompatActivity {

    /**
     * The {@link android.support.v4.view.PagerAdapter} that will provide
     * fragments for each of the sections. We use a
     * {@link FragmentPagerAdapter} derivative, which will keep every
     * loaded fragment in memory. If this becomes too memory intensive, it
     * may be best to switch to a
     * {@link android.support.v4.app.FragmentStatePagerAdapter}.
     */
    SectionsPagerAdapter mSectionsPagerAdapter;
    Button buttonSignUp;
    View view;

    /**
     * The {@link ViewPager} that will host the section contents.
     */
    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_walkthroughs);

        SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
        if(pref.getBoolean("activity_executed", false)){
            Intent intent = new Intent(this, Main.class);
            startActivity(intent);
            finish();
        } else {
            SharedPreferences.Editor ed = pref.edit();
            ed.putBoolean("activity_executed", true);
            ed.apply();
        }

        // Create the adapter that will return a fragment for each of the three
        // primary sections of the activity.
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) findViewById(R.id.pager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        CirclePageIndicator circleIndicator = (CirclePageIndicator)findViewById(R.id.titles);
        circleIndicator.setViewPager(mViewPager);

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_walkthrough_screen_no1, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


    /**
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to
     * one of the sections/tabs/pages.
     */
    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).

            switch (position){
                case 0:
                    return new Walkthroughs_screen_no1();
                case 1:
                    return new Walkthrough_screen_no2();
                case 2:
                    return new Walkthrough_screen_no3();
                case 3:
                    return new Walkthrough_screen_no4();
                case 4:
                    return new Walkthrough_screen_no5();
                default:
                    return new Walkthrough_screen_no5();
            }
        }

        @Override
        public int getCount() {
            // Show 5 total pages.
            return 5;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            Locale l = Locale.getDefault();
            switch (position) {
                case 0:
                    return getString(R.string.title_section1).toUpperCase(l);
                case 1:
                    return getString(R.string.title_section2).toUpperCase(l);
            }
            return null;
        }
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private static final String ARG_SECTION_NUMBER = "section_number";

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        public PlaceholderFragment() {
        }

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

}

下面是我的Walkthrough_screen_no5.java文件的代码:

代码语言:javascript
复制
public class Walkthrough_screen_no5 extends Fragment {

    View view;
    Button buttonSignUp;
    EditText et;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_walkthrough_screen_no5, container, false);
        et = (EditText) rootView.findViewById(R.id.signUp_phoneNumber);
        buttonSignUp = (Button) rootView.findViewById(R.id.buttonSignUp);
        buttonSignUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String editText = et.getText().toString();
                if(editText.isEmpty()) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setTitle("Oops!");
                    builder.setMessage("You forgot to enter your phone number.");
                    builder.setPositiveButton(android.R.string.ok, null);

                    AlertDialog dialog = builder.create();
                    dialog.show();
                } else {
                    Intent intent = new Intent(getActivity(), Main.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(intent);
                }
            }
        });
        return rootView;
    }
}

下面是我的AndroidManifest.xml文件的代码:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.abc.xxx" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:uiOptions="splitActionBarWhenNarrow" >
        <activity
            android:name=".Main"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".MyCredits"
            android:label="@string/title_activity_my_credits"
            android:parentActivityName=".Main" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.abc.xxx.Main" />
        </activity>
        <activity
            android:name=".AddMoreFriends"
            android:label="@string/title_activity_add_friends"
            android:parentActivityName=".Main" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.abc.xxx.Main" />
        </activity>
        <activity
            android:name=".Settings"
            android:label="@string/title_activity_settings"
            android:parentActivityName=".Main" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.abc.xxx.Main" />
        </activity>
        <activity
            android:name=".Help"
            android:label="@string/title_activity_help"
            android:parentActivityName=".Settings" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.abc.xxx.Settings" />
        </activity>
        <activity
            android:name=".Walkthroughs"
            android:label="@string/app_name"
            android:theme="@style/WalkthroughThemes"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

我是StackOverflow的新手,所以请合作。

提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2015-09-03 08:57:35

好的,在这段代码中

代码语言:javascript
复制
SharedPreferences pref = getSharedPreferences("ActivityPREF", Context.MODE_PRIVATE);
    if(pref.getBoolean("activity_executed", false)){
        Intent intent = new Intent(this, Main.class);
        startActivity(intent);
        finish();
    } else {
        SharedPreferences.Editor ed = pref.edit();
        ed.putBoolean("activity_executed", true);
        ed.apply();
    }

您正在检查是否是activity_executed布尔值,并根据它的值来决定是否启动您的主要活动,但从下一次开始,您将始终需要设置共享首选项"has_signedup“,这应该以您所做的方式简单地在Walkthrough_screen_no5片段中设置,并在您的活动中检查该值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32368487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档