Hello everyone, I am having a bit of trouble with my current application. With a button at the beginning of my app, I send out Intents for two activities, one gets a camera object, and starts a preview screen. On top of that, in a separate layout, there is an activity with a translucent view, which shows a resource image (the user is trying to get the image he is actually taking to align with the translucent image) and a couple of textviews displaying a target phone orientation as well as the user's current phone orientation.
Here is my problem: when I update the text value of one of my text views in my onSensorChanged() field, the system constantly reallocates 1.22MB and garbage collects it. I can only assume that this is because it is redrawing the entire layout with the translucent image and the text fields, because if I remove the view containing the translucent image from the layout, my text field updates 10x quicker and I don't have ridiculous heap growing / garbage collecting. I am wondering how to go about getting the text fields to update without redrawing the entire surface. I am very new to UI design, and this code was written by someone else before I took over the project, so I don't understand much of what is going on in the custom view he wrote to take care of the translucent image -- called MyView. I will post the code for the layout as well as the MyView code below. A reiteration of my goal -- I want to update the TextView text without the extraneous allocation / garbage collection that is coming as a result of having MyView included in the layout. Layout: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:id="@+id/home_container" android:layout_width="fill_parent" android:layout_height="fill_parent"> <infolab.geosim.MyView android:id="@+id/myView" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <LinearLayout android:id="@+id/LinearLayout01" android:layout_width="wrap_content" android:layout_height="wrap_content" xmlns:android="http:// schemas.android.com/apk/res/android" android:layout_gravity="bottom"> <TextView android:id="@+id/TargetDirTextView" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> <TextView android:id="@+id/CurrentDirTextView" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> </LinearLayout> </FrameLayout> MyView code: public class MyView extends View{ public MyView(Context context, int t) { super(context); } public MyView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onDraw(Canvas canvas) { java.io.InputStream is = null; if(Global.imageId == 0) { is = getResources().openRawResource(R.drawable.eeb); } else if(Global.imageId == 1) { is = getResources().openRawResource(R.drawable.phe); } else if(Global.imageId == 2) { is = getResources().openRawResource(R.drawable.rth); } else if(Global.imageId == 3) { is = getResources().openRawResource(R.drawable.eeb); } BitmapFactory.Options opts = new BitmapFactory.Options(); Bitmap bm; opts.inJustDecodeBounds = true; bm = BitmapFactory.decodeStream(is, null, opts); // now opts.outWidth and opts.outHeight are the dimension of the // bitmap, even though bm is null opts.inJustDecodeBounds = false; // this will request the bm opts.inSampleSize = 1; // scaled down by 4 bm = BitmapFactory.decodeStream(is, null, opts); Bitmap bm2 = bm.copy(Bitmap.Config.ARGB_8888, true); int[] pixelArray = new int[bm2.getHeight()*bm2.getWidth ()]; bm2.getPixels(pixelArray, 0, bm2.getWidth(), 0, 0, bm2.getWidth(), bm2.getHeight()); int i; for(i=0; i<pixelArray.length; i++) { pixelArray[i] ^= 0x55111111; } bm2.setPixels(pixelArray, 0, bm2.getWidth(), 0, 0, bm2.getWidth(), bm2.getHeight()); canvas.drawBitmap(bm2, 10, 10, null); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

