毕加索,图片视图没有得到刷新

时间:2016-10-26 06:04:56

标签: android picasso

我正在使用Picasso库将图像加载到图像视图中,在它第一次工作正常但之后它再次重复相同的图像,如果我回去并进行一些更改再次启动活动与图像。 url总是一样的,我已经搜索并应用了许多不能正常工作的变化请求帮助。

同时当我关闭应用程序并重新启动它时,它也没有刷新,当我点击浏览器上的URL时,它会显示更新的图像。

          Picasso.with(this)
            .load(Config.API_URL+"/sites/default/files/"+uiidd+".png")
            .memoryPolicy(MemoryPolicy.NO_CACHE)
            .networkPolicy(NetworkPolicy.NO_CACHE)
            .into(imageView); 






     public class Activity_result extends AppCompatActivity {
    Toolbar toolbar;
    private ImageView imageView;
    String uiidd;

    Button testagain_btn;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_result);

        imageView = (ImageView) findViewById(R.id.imageView_chart);
        toolbar = (Toolbar) findViewById(R.id.tool_barresult);
        testagain_btn=(Button)findViewById(R.id.btn_testagain);



        setSupportActionBar(toolbar);
        uiidd = MyApplication.getInstance().getUid();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getWindow().setStatusBarColor(getResources().getColor(R.color.color_darkgreen));
        }

       Picasso.with(this)
                .load(Config.API_URL+"/sites/default/files/"+uiidd+".png")
                .into(imageView);
      /*  new Thread(new Runnable() {
            @Override
            public void run() {
                Glide.get(Activity_result.this).clearDiskCache();
            }
        }).start();

      Glide.with(this)
                .load(Config.API_URL+"/sites/default/files/"+uiidd+".png")
              .skipMemoryCache(true)
              .diskCacheStrategy(DiskCacheStrategy.NONE)
              //.signature(new StringSignature(System.currentTimeMillis()))
              .into(imageView);*/

        resultjsonrequest();
     testagain_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               /* Intent i = new Intent(Activity_result.this,Activity_knowStatus.class);
                startActivity(i);*/

                final Dialog dialog = new Dialog(Activity_result.this);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.custom_dialoghealthdata);

                dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

                ImageView dialogButtonCancel = (ImageView) dialog.findViewById(R.id.imageView_close);
                Button dialogButtonOk = (Button) dialog.findViewById(R.id.btn_ok);
                // Click cancel to dismiss android custom dialog box
                dialogButtonCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });

                // Your android custom dialog ok action
                // Action for custom dialog ok button click
                dialogButtonOk.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent i = new Intent(Activity_result.this,Activity_knowStatus.class);
                        startActivity(i);
                    }
                });

                dialog.show();






            }
        });




    }

    @Override
    protected void onResume() {
        super.onResume();
        Picasso.with(this)
                .load(Config.API_URL+"/sites/default/files/"+uiidd+".png")
                .into(imageView);
    }

    /* @Override
    public void onBackPressed()
    {

finish();

    }*/

    private void resultjsonrequest() {

        Util.showProDialog(Activity_result.this,"Loading....");

        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
                Config.API_URL+"/profile-result-json?userProfileID="+uiidd+"", null, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {


                try {

                    String txt_totalscore1 = response.getString("patient_score");
                    txtvw_totalscore.setText(txt_totalscore1);

                    String txt_chol1 = response.getString("Cholesterol");
                    txt_chol.setText(txt_chol1);
                    String cholcolor = response.getString("cholesterolPointColor");
                    linear_chol.setBackgroundColor(Color.parseColor(cholcolor));

                    String txt_trigly1 = response.getString("Triglycerides");
                    txt_trigly.setText(txt_trigly1);
                    String triglycolor = response.getString("triglycerideScoreColor");
                    linear_trigly.setBackgroundColor(Color.parseColor(triglycolor));

                    String txt_hdlchol1 = response.getString("HDLCholesterol %");
                    txt_hdl_chol.setText(txt_hdlchol1);
                    String hdlchl1color = response.getString("hDL_cholesterol_scoreColor");
                    linear_hdl_chol.setBackgroundColor(Color.parseColor(hdlchl1color));

                    String txt_sysbp1 = response.getString("SystolicBP");
                    txt_systolicbp.setText(txt_sysbp1);
                    String systoiccolor = response.getString("systolic_bp_scoreColor");
                    linear_systolicbp.setBackgroundColor(Color.parseColor(systoiccolor));

                    String txt_disys1 = response.getString("DiastolicBP");
                    txt_disystolicbp.setText(txt_disys1);
                    String disyscolor = response.getString("diastolic_bp_scoreColor");
                    linear_disystolicbp.setBackgroundColor(Color.parseColor(disyscolor));

                    String txsugarf1 = response.getString("Blood Sugar Fasting (FF)");
                    txt_bloodsugarff.setText(txsugarf1);
                    String sugarfcolor = response.getString("bl_glucode_ff_scoreColor");
                    linear_bloodsugarff.setBackgroundColor(Color.parseColor(sugarfcolor));


                    String txsugarp1 = response.getString("Blood Sugar (PP)");
                    txt_bloodsugarpp.setText(txsugarp1);
                    String sugarpcolor = response.getString("bl_glucose_pp_scoreColor");
                    linear_bloodsugarpp.setBackgroundColor(Color.parseColor(sugarpcolor));

                    String txsmoking1 = response.getString("Smoking");
                    txt_smoking.setText(txsmoking1);
                    String smokingcolor = response.getString("Smoking_ScoreColor");
                    linear_smoking.setBackgroundColor(Color.parseColor(smokingcolor));


                    String txbmi = response.getString("BMI");
                    txt_bmi.setText(txbmi);
                    String bmicolor = response.getString("BMI_ScoreColor");
                    linear_bmi.setBackgroundColor(Color.parseColor(bmicolor));

                    String txwalking1 = response.getString("Walking");
                    txt_walking.setText(txwalking1);
                    String walkingcolor = response.getString("walkingPointColor");
                    linear_walking.setBackgroundColor(Color.parseColor(walkingcolor));

                    String txt_oil1 = response.getString("Oil Intake");
                    txt_oil.setText(txt_oil1);
                   String oilcolor = response.getString("oil_ghee_intake_scoreColor");
                   linear_oil.setBackgroundColor(Color.parseColor(oilcolor));


                    String txmilk1 = response.getString("MilkDairy Intake");
                    txt_milk.setText(txmilk1);
                    String milkcolor = response.getString("milk_dairy_intake_scoreColor");
                    linear_milk.setBackgroundColor(Color.parseColor(milkcolor));

                    String txfruit1 = response.getString("Fruits Intake");
                    txt_fruit.setText(txfruit1);
                    String fruitcolor = response.getString("Vegitable_ScoreColor");
                    linear_fruit.setBackgroundColor(Color.parseColor(fruitcolor));

                    String txt_vegetable1 = response.getString("Vegetables Intake");
                    txt_vegetable.setText(txt_vegetable1);
                    String vegetablecolor = response.getString("vegetable_you_intake_scoreColor");
                    linear_vegetable.setBackgroundColor(Color.parseColor(vegetablecolor));

                    String txnonveg1 = response.getString("Animal Food");
                    txt_nonveg.setText(txnonveg1);
                    String nonvegcolor = response.getString("intake_non_veg_scoreColor");
                    linear_nonveg.setBackgroundColor(Color.parseColor(nonvegcolor));

                    String txyoga1 = response.getString("Yoga");
                    txt_yoga.setText(txyoga1);
                    String yogacolor = response.getString("yoga_or_stretching_exercis_scoreColor");
                    linear_yoga.setBackgroundColor(Color.parseColor(yogacolor));

                    String txmeditation1 = response.getString("MeditationPranayam");
                    txt_meditation.setText(txmeditation1);
                    String meditationcolor = response.getString("meditation_prayer_scoreColor");
                    linear_meditation.setBackgroundColor(Color.parseColor(meditationcolor));

                    String txstress1 = response.getString("Stress Management");
                    txt_stress.setText(txstress1);
                    String stresscolor = response.getString("stress_mgmt_scoreColor");
                    linear_stress.setBackgroundColor(Color.parseColor(stresscolor));






                } catch (JSONException e) {
                    e.printStackTrace();
                    Util.showMessageDialog(Activity_result.this, "Server error! Try Again");
                }
                Util.dimissProDialog();
            }
        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
               Util.dimissProDialog();
                Util.showMessageDialog(Activity_result.this, "Server error! Try Again");
            }
        });
        jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
                10000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

        // Adding request to request queue
       // MyApplication.getInstance().addToRequestQueue(jsonObjReq);
        RequestQueue requestQueue = Volley.newRequestQueue(this);
        requestQueue.add(jsonObjReq);
    }






}

2 个答案:

答案 0 :(得分:1)

我已经得到了上述问题的解决方案,问题的主要原因是与更新的图像相同的url,所以我每次都会随机生成一个数字添加一个令牌,因此url会被更改并且图像得到更新。

    double token=0;
    token=Math.random();
    Picasso.with(getApplicationContext()).invalidate("");
    Picasso.with(this)
                 .load(Config.API_URL+"/sites/default/files/"+uiidd+".png?"+token)
            .memoryPolicy(MemoryPolicy.NO_CACHE)
            .networkPolicy(NetworkPolicy.NO_CACHE)
            .into(imageView_chartt);

答案 1 :(得分:0)

试试这个:

Picasso.with(this)
        .load(Config.API_URL+"/sites/default/files/"+uiidd+".png")
        .into(imageView);

缓存图像总是一个好主意,直​​到每个实例都需要强制刷新

如果您希望每次重新加载图片以从任何其他位置返回此活动,请从活动的onResume而不是onCreate调用此内容