dongyanjing5975 2019-08-18 22:34
浏览 63

首次调用后Android响应值未更新

I'm creating my first Android APP but I'm fighting some problems that I actually don't understand how to solve.

My app have a point system and every day I give some points to the users by just doing a Login and clicking a button. But aparently I'm having an issue because the value of the response is only updating when I log out and log in again or when I uninstall and install the app again, if I close and then re-open the app , the value is still the same.

For example, if I'm opening the app for the first time, clicking the button it will say "Here are your 10 points for Login Daily", then I click the button again and the app will say "Here are your 10 points for Login Daily", but the weird part here is that the server don't add the points to the user the second time, so either the response returns a wrong state or the android app is showing stored weird data. Then if you Re-Login or Re-Install the next time that you click it will say "You have to wait X Hours"

Here is my code,

Android Request:

private void dailyCheckin(final ProgressDialog pDialog) {
    //first getting the values
    final String reg_user_id=String.valueOf(SharedPref.getInstance(getApplicationContext()).getUserID());
    //Call our volley library
    StringRequest stringRequest = new StringRequest(Request.Method.POST, Constant.DAILYCHECKIN,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject obj = new JSONObject(response);
                        if (obj.getBoolean("error")) {
                            pDialog.hide();
                            Toast.makeText(getApplicationContext(),
                                    getString(R.string.newdailyreward)
                                            +" "+obj.getString("hours")+" "+
                                            getString(R.string.hours)
                                            +" "+obj.getString("minutes")+" "+
                                            getString(R.string.minutes), Toast.LENGTH_SHORT).show();
                        } else {
                            pDialog.hide();
                            Toast.makeText(getApplicationContext(),
                                    getString(R.string.rewardsuccess)
                                            +" "+obj.getString("message")+" "+
                                            getString(R.string.rewardpoints)
                                    , Toast.LENGTH_SHORT).show();

                        }
                    } catch (JSONException e) {
                        pDialog.hide();
                        e.printStackTrace();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    pDialog.hide();
                    error.printStackTrace();
                }
            }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("user_id", reg_user_id);

            return params;
        }
    };
    VolleySingleton.getInstance(FreePointsActivity.this).addToRequestQueue(stringRequest);
}//dailyCheckin

PhP Response Function:

    elseif (isset($_GET['dailycheckin'])) {
    $id=intval($_POST['user_id']);


        $daily="Daily Checkin";





        $sql='select * from rewardpoints_points where user_id='.$id.' AND app_name="'.$daily.'"  ORDER BY date_operation DESC;';
        $res=$cnx->query($sql);
        $data=$res->fetchAll(PDO::FETCH_OBJ)[0];


if (empty($data)) {

                $s='select daily_chekin_points from rewardpoints_settings';
                $r=$cnx->query($s);
                $d=$r->fetchAll(PDO::FETCH_OBJ)[0];
                $points=$d->daily_chekin_points;
                $sql="insert into rewardpoints_points values(NULL,'".$id."',0,'".$daily."','".$points."',NOW(),0)";
                if($cnx->exec($sql)){ 
                    $response['error'] = false;
                    $response['message'] = $points; 
                }


    }
    else{

        $newreward= strtotime( $data->date_operation ) + 24 * 3600;
        if ($newreward<=time()) {
            //echo "you can get";
                $s='select daily_chekin_points from rewardpoints_settings';
                $r=$cnx->query($s);
                $d=$r->fetchAll(PDO::FETCH_OBJ)[0];
                $points=$d->daily_chekin_points;
                $sql="insert into rewardpoints_points values(NULL,'".$id."',0,'".$daily."','".$points."',NOW(),0)";
                if($cnx->exec($sql)){ 
                    $response['error'] = false;
                    $response['message'] = $points; 
                }

        }//$newreward<=time()
        else{
            //echo "you can not";
        $response['error'] = true;
        $time=time()-$newreward;
        $m = floor($time / 60)*-1;
        $hours = floor($m / 60);
        $minutes = ($m % 60);
        $response['hours'] = $hours;
        $response['minutes'] = $minutes;
        }

    }
    }//dailycheckin
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能