小编Sha*_*ank的帖子

SharedPreference未按预期工作

我有一个活动,我只想在第一次运行应用程序时运行.我检查了一个返回布尔值的指定共享首选项.如果它返回true,它将被启动并且它将被设置为false,以便下次打开应用程序时它不会运行.但我的实施出错了.每次打开BeforMain1活动都会被打开.有人可以告诉我我的代码有什么问题吗?

sharedPreferences = getSharedPreferences("ShaPreferences", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor=sharedPreferences.edit();
            boolean  firstTime=sharedPreferences.getBoolean("first", true);
            if(firstTime) {
                editor.putBoolean("first",false);
                Intent intent = new Intent(SplashScreen.this, BeforeMain1.class);
                startActivity(intent);
            }
            else
            {
                Intent intent = new Intent(SplashScreen.this, MainActivity.class);
                startActivity(intent);
            }
Run Code Online (Sandbox Code Playgroud)

android sharedpreferences

4
推荐指数
1
解决办法
6341
查看次数

从批处理脚本中的变量中减去数字

我是批处理脚本的新手,所以请宽容地对待这个问题。当我从“TodayDay”变量中减去 1 时,该值没有更新。下面是该行。

set /a "TodayDay=%TodayDay%-1"
Run Code Online (Sandbox Code Playgroud)

我的用例是查找今天的日期是否小于“lastOpenedDate”变量,我想将“lastOpenedDate”设置为昨天的日期

set lastOpenedDate=2017-12-22
IF %TodayYear%-%TodayMonth%-%TodayDay% LSS %lastOpenedDate% (   
  echo Before Subtraction TodayDay is %TodayDay%
  set /a "TodayDay=%TodayDay%-1"
  echo After Subtraction TodayDay is %TodayDay%
)
Run Code Online (Sandbox Code Playgroud)

当我运行上面的代码时,输​​出是:

Before Subtraction TodayDay is 20
After Subtraction TodayDay is 20
Run Code Online (Sandbox Code Playgroud)

我从下面提到的代码中得到了其他变量值

for /F "skip=1 delims=" %%F in ('
    wmic PATH Win32_LocalTime GET Day^,Month^,Year /FORMAT:TABLE
') do (
    for /F "tokens=1-3" %%L in ("%%F") do (
        set TodayDay=0%%L
        set TodayMonth=0%%M
        set TodayYear=%%N
    )
)
set TodayDay=%TodayDay:~-2%
set TodayMonth=%TodayMonth:~-2%
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

batch-file subtraction

1
推荐指数
1
解决办法
1万
查看次数