【问题标题】:Do not show Onboarding activity again on button click [duplicate]不要在按钮单击时再次显示入职活动[重复]
【发布时间】:2021-07-05 10:06:25
【问题描述】:

我有一个内置于 Android 工作室的 Android 应用,在这个应用上,我正在使用演练活动。

如何设置此活动,以在单击按钮时不再显示此页面。

这是函数“public void onFinishButtonPressed()”,这是我在按钮上添加了onlick监听器的部分,应该如何完成,一旦调用了这个函数,这个活动就不会再次打开。

我试图实现一个代码来仅在第一次运行时显示活动,但这仍然不是预期的结果,我真的希望这个页面一直显示,直到点击那个按钮。

提前感谢您的帮助。

我的代码;

package com.frigate.vpn.view;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.frigate.vpn.R;
import com.shashank.sony.fancywalkthroughlib.FancyWalkthroughActivity;
import com.shashank.sony.fancywalkthroughlib.FancyWalkthroughCard;

import java.util.ArrayList;
import java.util.List;

public class Walkthrough extends FancyWalkthroughActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FancyWalkthroughCard fancywalkthroughCard1 = new FancyWalkthroughCard("Welcome to Frigate Media VPN", "Let me show you why so many people love Frigate Media VPN", R.drawable.find_restaurant1);
        FancyWalkthroughCard fancywalkthroughCard2 = new FancyWalkthroughCard("We Protect your Privacy", "Internet access is mind free, we'll keep you safe",R.drawable.pickthebest);
        FancyWalkthroughCard fancywalkthroughCard3 = new FancyWalkthroughCard("Fast & Limitless!", "We provide you the fastest servers without limits.",R.drawable.chooseurmeal);
        FancyWalkthroughCard fancywalkthroughCard4 = new FancyWalkthroughCard("Frigate Media VPN is 100% Free", "You do not have to worry about paying for expensive VPN, we give you everything for free.",R.drawable.mealisonway);

        fancywalkthroughCard1.setBackgroundColor(R.color.white);
        fancywalkthroughCard1.setIconLayoutParams(300,300,0,0,0,0);
        fancywalkthroughCard2.setBackgroundColor(R.color.white);
        fancywalkthroughCard2.setIconLayoutParams(300,300,0,0,0,0);
        fancywalkthroughCard3.setBackgroundColor(R.color.white);
        fancywalkthroughCard3.setIconLayoutParams(300,300,0,0,0,0);
        fancywalkthroughCard4.setBackgroundColor(R.color.white);
        fancywalkthroughCard4.setIconLayoutParams(300,300,0,0,0,0);
        List<FancyWalkthroughCard> pages = new ArrayList<>();

        pages.add(fancywalkthroughCard1);
        pages.add(fancywalkthroughCard2);
        pages.add(fancywalkthroughCard3);
        pages.add(fancywalkthroughCard4);

        for (FancyWalkthroughCard page : pages) {
            page.setTitleColor(R.color.black);
            page.setDescriptionColor(R.color.black);
        }
        setFinishButtonTitle("Get Started");
        showNavigationControls(true);
        setColorBackground(R.color.white);
        //setImageBackground(R.drawable.restaurant);
        setInactiveIndicatorColor(R.color.grey_600);
        setActiveIndicatorColor(R.color.colorGreen);
        setOnboardPages(pages);

    }

    @Override
    public void onFinishButtonPressed() {

        Intent intent = new Intent(Walkthrough.this, MainActivity.class);
        startActivity(intent);
        finish();

    }
}

【问题讨论】:

    标签: java android


    【解决方案1】:

    为什么不直接使用名为“isFinishedButtonPressed”的全局布尔变量,默认设置为 false,按下按钮时将其设置为 true,并且在正确的条件下它应该做你想做的事,不?

    【讨论】:

    • 那行不通,因为那不是持久存储。
    猜你喜欢
    • 2016-06-22
    • 2020-07-28
    • 2021-05-22
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 2015-12-28
    • 2017-12-07
    • 2015-11-12
    相关资源
    最近更新 更多