仅在首次使用应用程序时打开 TapTarget
Open TapTarget only on first use of application
我有一个 TapTarget
当我的应用程序打开时,我只希望它在应用程序第一次启动时打开,我如何存储一个值以确保它不会在其他应用程序上再次打开启动,这是我尝试过的但它不起作用,TapTarget
每次应用程序启动时都会打开。
代码:
realm.executeTransaction { realm ->
val result = Taptarget()
result.cal = ""
result.chat = ""
result.depfpsc = ""
result.info = ""
result.module = ""
realm.insert(result)
}
realm.executeTransaction { realm ->
val result = realm.where(Taptarget::class.java).findFirst()!!
if(result.module == "Y")
{
}
else
{
if (mFabPrompt != null) {
return@executeTransaction
}
mFabPrompt = MaterialTapTargetPrompt.Builder(this@MainActivity)
.setTarget(findViewById<View>(R.id.navigation_modules))
.setPrimaryText("Send your first email")
.setSecondaryText("Tap the envelope to start composing your first email")
.setIconDrawable(resources.getDrawable(R.drawable.ic_folder_black_24dp))
.setBackgroundColour(resources.getColor(R.color.colorAccentTrans))
.setAnimationInterpolator(FastOutSlowInInterpolator())
.setPromptStateChangeListener { prompt, state ->
if (state == MaterialTapTargetPrompt.STATE_FOCAL_PRESSED || state == MaterialTapTargetPrompt.STATE_DISMISSING) {
mFabPrompt = null
}
}
.create()
mFabPrompt!!.show()
result.depfpsc = "Y"
realm.insertOrUpdate(result!!)
}
}
我不确定你用什么语言写的代码。但是让我在java中解释一下我精通的地方。您可以轻松地将其改编为任何其他语言。
首先像这样创建一个 class PreferencesManager:
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);
}
}
现在每 activity,你必须检查应用程序是否是第一次启动:
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
}
这可能不是您要找的确切答案。但这可能会为您指明正确的方向:)
我有一个 TapTarget
当我的应用程序打开时,我只希望它在应用程序第一次启动时打开,我如何存储一个值以确保它不会在其他应用程序上再次打开启动,这是我尝试过的但它不起作用,TapTarget
每次应用程序启动时都会打开。
代码:
realm.executeTransaction { realm ->
val result = Taptarget()
result.cal = ""
result.chat = ""
result.depfpsc = ""
result.info = ""
result.module = ""
realm.insert(result)
}
realm.executeTransaction { realm ->
val result = realm.where(Taptarget::class.java).findFirst()!!
if(result.module == "Y")
{
}
else
{
if (mFabPrompt != null) {
return@executeTransaction
}
mFabPrompt = MaterialTapTargetPrompt.Builder(this@MainActivity)
.setTarget(findViewById<View>(R.id.navigation_modules))
.setPrimaryText("Send your first email")
.setSecondaryText("Tap the envelope to start composing your first email")
.setIconDrawable(resources.getDrawable(R.drawable.ic_folder_black_24dp))
.setBackgroundColour(resources.getColor(R.color.colorAccentTrans))
.setAnimationInterpolator(FastOutSlowInInterpolator())
.setPromptStateChangeListener { prompt, state ->
if (state == MaterialTapTargetPrompt.STATE_FOCAL_PRESSED || state == MaterialTapTargetPrompt.STATE_DISMISSING) {
mFabPrompt = null
}
}
.create()
mFabPrompt!!.show()
result.depfpsc = "Y"
realm.insertOrUpdate(result!!)
}
}
我不确定你用什么语言写的代码。但是让我在java中解释一下我精通的地方。您可以轻松地将其改编为任何其他语言。
首先像这样创建一个 class PreferencesManager:
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);
}
}
现在每 activity,你必须检查应用程序是否是第一次启动:
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
}
这可能不是您要找的确切答案。但这可能会为您指明正确的方向:)