Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 仅在首次使用应用程序时打开TapTarget_Android_Realm_Target - Fatal编程技术网

Android 仅在首次使用应用程序时打开TapTarget

Android 仅在首次使用应用程序时打开TapTarget,android,realm,target,Android,Realm,Target,我有一个TapTarget当我的应用程序打开时,我只希望它在应用程序第一次启动时打开,我如何存储一个值以确保它不会在其他启动时再次打开,这是我尝试的,但它不起作用,TapTarget在应用程序每次启动时都会打开 代码: realm.executeTransaction{realm-> val result=Taptarget() result.cal=“” result.chat=“” result.depfsc=“” result.info=“” result.module=“” realm.

我有一个
TapTarget
当我的应用程序打开时,我只希望它在应用程序第一次启动时打开,我如何存储一个值以确保它不会在其他启动时再次打开,这是我尝试的,但它不起作用,
TapTarget
在应用程序每次启动时都会打开

代码:

realm.executeTransaction{realm->
val result=Taptarget()
result.cal=“”
result.chat=“”
result.depfsc=“”
result.info=“”
result.module=“”
realm.insert(结果)
}
realm.executeTransaction{realm->
val result=realm.where(Taptarget::class.java).findFirst()!!
如果(result.module==“Y”)
{
}
其他的
{
if(mFabPrompt!=null){
return@executeTransaction
}
mFabPrompt=MaterialTargetPrompt.Builder(this@MainActivity)
.setTarget(findViewById(R.id.navigation_模块))
.setPrimaryText(“发送您的第一封电子邮件”)
.setSecondaryText(“轻触信封开始撰写第一封电子邮件”)
.setIconDrawable(resources.getDrawable(R.drawable.ic\u folder\u black\u 24dp))
.SetBackgroundColor(参考资料.getColor(R.color.colorAccentTrans))
.setAnimationInterpolator(FastOutSlowInInterpolator())
.setPromptStateChangeListener{prompt,state->
如果(状态==MaterialTargetPrompt.state_FOCAL_按下| |状态==MaterialTargetPrompt.state_DISMISSING){
mFabPrompt=null
}
}
.create()
mFabPrompt!!.show()
result.depfsc=“Y”
realm.insertOrUpdate(结果!!)
}
}

我不确定您是用什么语言编写代码的。但让我用java解释一下我精通的语言。您可以轻松地将其应用于任何其他语言

首先创建一个类首选项管理器,如下所示:

public class PreferencesManager {

SharedPreferences pref;
SharedPreferences.Editor editor;
Context _context;

// shared pref mode
int PRIVATE_MODE = 0;

// Shared preferences file name
private static final String PREF_NAME = "splash-welcome";

// Shared preference variable name
private static final String IS_FIRST_TIME_LAUNCH = "IsFirstTimeLaunch";

// Constructor
public PrefManager(Context context) {
    this._context = context;
    pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);
    editor = pref.edit();
}

// This method to be used as soon as the fist time launch is completed to update the 
// shared preference
public void setFirstTimeLaunch(boolean isFirstTime) {
    editor.putBoolean(IS_FIRST_TIME_LAUNCH, isFirstTime);
    editor.commit();
}

// This method will return true of the app is launched for the first time. false if 
// launched already 
public boolean isFirstTimeLaunch() {
    return pref.getBoolean(IS_FIRST_TIME_LAUNCH, true);
}
}
现在,在每个活动中,您都必须检查应用程序是否首次启动:

 PreferencesManager preferencesManager = new PreferencesManager (this);
 if (!preferencesManager.isFirstTimeLaunch()) {
    // Set shared preference value to false so that this block will not be called 
    // again until your user clear data or uninstall the app
    preferencesManager.setFirstTimeLaunch(false); 
    // Write your logic here
    }

这可能不是您正在寻找的确切答案。但这可能会为您指明正确的方向:)

sharedpreferences@KarthicSrinivasan如何使用首选项首次存储activities@KarthicSrinivasan对于每项活动,他都在使用Kotlin,这是自2017年5月以来Android开发的官方支持语言。
 PreferencesManager preferencesManager = new PreferencesManager (this);
 if (!preferencesManager.isFirstTimeLaunch()) {
    // Set shared preference value to false so that this block will not be called 
    // again until your user clear data or uninstall the app
    preferencesManager.setFirstTimeLaunch(false); 
    // Write your logic here
    }