2016-10-26 10 views
0

Picassoライブラリを使用して画像を画像表示に読み込みますが、最初はうまくいきますが、その後は同じ画像が繰り返されます。 URLは常に同じです、私は検索し、多くの変更を適用していないその作業を助けてください。Picasso、画像表示がリフレッシュされない

私は同時にアプリケーションを終了して再起動しても、リフレッシュされません。ブラウザで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); 
    } 






} 
+1

するTryグライド:https://github.com/bumptech/glide – elmontoya7

+0

私はすでにグライドを試してみましたが、同じ問題が –

+0

あなたはすべてのTextViewsとLinearLayoutsがあなたの問題の原因である可能性がありますと思いますが存在しますか?そうでない場合は、コードを編集して関連する部分のみを投稿してください。 – 0X0nosugar

答えて

1

問題の主な理由は、更新されたイメージと同じURLだったので、毎回ランダムに生成された番号を持つ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); 
0

はこの試してみてください。

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

第二代わりにあなたの活動のonResumeからこれを呼び出す強制リフレッシュがすべてのインスタンスで必要とされるまで、常にあなたのイメージをキャッシュすることをお勧めしますonCreateの場合は、このアクティビティに戻るたびにイメージを再読み込みして他の場所から戻したい場合は

+0

私はそれが今動作していない、私は追加したい1つは、私は、アプリケーションを閉じて、それも同じ画像を表示するそれを再起動 –

+0

あなたのコードを共有することはできますか? – Ak9637

+0

自分のコードを追加しました –

関連する問題