【问题标题】:My Activity is getting slow as i am fetching images from other activity当我从其他活动中获取图像时,我的活动变得缓慢
【发布时间】:2014-04-09 12:20:59
【问题描述】:

当我从其他活动中获取图像时,我的活动变得越来越慢 如果我减小图像大小,我应该怎么做才能使活动快速。 请帮我解决这个问题并告诉我应该使用什么来共享偏好来从其他活动中获取图像。 谢谢 这是代码

            title=(EditText) findViewById(R.id.title);
    description=(EditText) findViewById(R.id.description);
    phonenumber=(EditText) findViewById(R.id.phonenumber);
    email=(EditText) findViewById(R.id.email);
    price=(EditText) findViewById(R.id.price);
    postadd=(Button) findViewById(R.id.button_post);

    location=(TextView) findViewById(R.id.location);
    category=(TextView) findViewById(R.id.category);
    subcategory=(TextView) findViewById(R.id.subcategory);



    imageview1=(ImageView) findViewById(R.id.image1);
    imageview2=(ImageView) findViewById(R.id.image2);
    imageview3=(ImageView) findViewById(R.id.image3);
    imageview4=(ImageView) findViewById(R.id.image4);



    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    locationname = preferences.getString("Location", "Location");

    SharedPreferences preferences1 = PreferenceManager.getDefaultSharedPreferences(this);
    categoryname = preferences1.getString("categoryname", "categoryname");

    SharedPreferences imagepath1 = PreferenceManager.getDefaultSharedPreferences(this);
    selectedImagePath1 = imagepath1.getString("picturePath1", "picturePath1");


    SharedPreferences imagepath2 = PreferenceManager.getDefaultSharedPreferences(this);
    selectedImagePath2 = imagepath2.getString("picturePath2", "picturePath2");

    SharedPreferences imagepath3 = PreferenceManager.getDefaultSharedPreferences(this);
    selectedImagePath3 = imagepath3.getString("picturePath3", "picturePath3");

    SharedPreferences imagepath4 = PreferenceManager.getDefaultSharedPreferences(this);
    selectedImagePath4 = imagepath4.getString("picturePath4", "picturePath4");



     AQuery aq = new AQuery(PostAddActivity.this);

     String imageUrl1 = selectedImagePath1;            
     aq.id(imageview1).image(imageUrl1);

     String imageUrl2 = selectedImagePath2;            
     aq.id(imageview2).image(imageUrl2);

     String imageUrl3 = selectedImagePath3;            
     aq.id(imageview3).image(imageUrl3);

     String imageUrl4 = selectedImagePath4;            
     aq.id(imageview4).image(imageUrl4);



    location.setText(locationname);
    category.setText(categoryname);
    subcategory.setText(subcategoryname);
    subcategory.setVisibility(View.VISIBLE);

    postadd.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v)
        {                       

            final String email1 = email.getText().toString().trim();
            final String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";


            if(title.getText().toString().equalsIgnoreCase(""))
            {
                Toast.makeText(PostAddActivity.this, "Fill your name !!!", Toast.LENGTH_SHORT).show();
            }
            else if(description.getText().toString().equalsIgnoreCase(""))
            {
                Toast.makeText(PostAddActivity.this, "Fill the Description !!!", Toast.LENGTH_SHORT).show();
            }
            else if (!email1.matches(emailPattern))
            { 
                Toast.makeText(PostAddActivity.this, "Email id is invalid !!!", Toast.LENGTH_SHORT).show();
            }


            new GetData().execute();


        }
        });

}

private class GetData extends AsyncTask<String, String, String> 
{



    @Override
    protected String doInBackground(String... params)
    {
           String Title = title.getText().toString();
           String Description = description.getText().toString().trim();
           String PhoneNumber = phonenumber.getText().toString();
           String Email = email.getText().toString();
           String Price = price.getText().toString();
        try
           {
            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet("http://tradewale.com/open/tradedata.php?home_cat=1");
            HttpResponse response = httpclient.execute(httpget);
            BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String line = "";
            String NL = System.getProperty("line.separator");
            while ((line = in.readLine()) != null) 
            {
                sb.append(line + NL);
            }
            in.close();
            String result = sb.toString();
            System.out.println(result);

            JSONObject obj = new JSONObject(result);
             value = obj.getString("Success");

                }
        catch (Exception e) 
        {
            e.printStackTrace();

            }

        return value;

    }
    @Override
    protected void onPostExecute(String result) 
    {
         int val=Integer.parseInt(value);
         if (val==1)
         {
            Toast.makeText(PostAddActivity.this, "Thank you For Inquiry ", Toast.LENGTH_LONG).show();
                finish();
         }

         else
         {
             Intent in = new Intent(getApplicationContext(), PostAddActivity.class);

                 startActivity(in);
         }
     }

}

【问题讨论】:

    标签: android file bitmap imageview bitmapfactory


    【解决方案1】:

    我看到您使用了查询...只需使用此选项:

    aq.id(imageview1).image(imageUrl, true, true, 200, 0); //200px width
    

    【讨论】:

    • 不客气 :) 。如果此答案解决了您的问题,请接受。祝你有美好的一天
    • 需要问一个事情 simas 你在吗
    • 在 fb 或提供 id 以便我可以轻松与您交谈
    • 如何通过 json 将图片发送到服务器
    • 这是一个完全不同的问题。首先你必须自己尝试,然后如果你有问题,你可以发布另一个问题。
    猜你喜欢
    • 2019-04-22
    • 1970-01-01
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    • 2017-04-13
    相关资源
    最近更新 更多