当我从其他活动中获取图像时,我的活动变得越来越慢

时间:2014-04-09 12:21:00

标签: android file bitmap imageview bitmapfactory

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

            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);
         }
     }

}

1 个答案:

答案 0 :(得分:0)

我看到你使用了aquery ......只需使用这个选项:

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