如何重置计数器?

时间:2016-06-04 13:31:04

标签: android count launch

我想在应用达到10次发布时展示插页式广告。所以我用左计算他们

OnCreate{
 prefs = getPreferences(Context.MODE_PRIVATE);
    editor = prefs.edit();
    totalCount = prefs.getInt("counter", 0);
    totalCount++;
    editor.putInt("counter", totalCount);
    editor.commit(); }


当totalCount = 10时,我运行add:

       if(totalCount==10){

                fullScreenAd2.show();

            }


现在我要重置totalCount,我该怎么做? 我知道调用totalCount ++会增加1点而totalCount--会删除1点。但是如何将其重置为0?

2 个答案:

答案 0 :(得分:0)

我认为你可以在它变为10后将其重置为0.例如:

   if(totalCount==10){
            fullScreenAd2.show();
            totalCount=0;  // and i think that, this should do it...
                editor.putInt("counter", totalCount); // call editor to save
                editor.commit();                      //totalCount's value
        }`

答案 1 :(得分:0)

以下内容应该有效:

TouchableHighlight