最新用户评论
ADIDDAS:
dddddd:
dddddd:
multithreaded:
to 贝壳:
贝壳:
根本不相干:
Brize_lu:
HS老童:
westerma :
原锐捷研发人员:
何必呢:
Michael:
兴隆记肇庆特产:
DMOLD模具设计:
独孤九贱:
xueshan:
stevenlee:
Michael:
小智:
xaiolos:
ru ellw:
0101010101010:
hahaha:
养殖专业户:
a10jliu:
chairman mao:
理客:
ZengLeiPro:
缓存一致性非常非常难:
张俊杰:
仁者见仁,智者见智:
路客:
Ma Ling:
Lucifer:
yimiqi:
宋伟:
xueshan:
宫长辉:
麦克:
卖龙:
Ma Ling:
muxiqingyang009:
siumem:
狐说:
yyxiaoma:
临时:
最新文章
文章分类
文章存档
| 2010-09-06 07:11
不好意思,貌似别人在这里发表文章都是为大家提供信息,我今天在这里发表文章主要是咨询与讨论。
业界做数据交换机的厂家不在少数,但是能做分布式交换机的要相对少一些,而能把分布式交换机做好的更是为数不多,我说的做好是架构合理,系统稳定,而且要能支持真正的热备份。据我所知,Cisco, Juniper, HuaWei, H3C, Alcatel等都号称做得很好(真正好不好我不知道)
在这个坛子上混的人应该不少高手,甚至可能有人对上述厂家的实现细节也有了解。这里向大家请教几个问题,欢迎大家积极发表意见。
1. 说到HA(High Availability, 通常就是指热备份),好几个厂家都宣称支持,但是我相信支持的程度不同,也许有的只是比cold standby强一点?有的能做到NSF(Non Stop Forwarding),还有的能做到很牛的NSR(Non Stop Routing)? 不管是NSF还是NSR,要实时同步这么多数据,处理能力是否跟得上?主备CPU之间的数据量岂不是很大?而要做到NSR,连路由协议都不需要重新学习?不知道各个厂家是怎么实现的?据我的了解,好像H3C和Huawei都并没有做到真正意义上的HA.是不是有些厂家使用graceful restart来做L3的HA呢?Cisco和Juniper真的能做到这么完美?
有点怀疑
2. 大公司的线卡类型都很多,而且都会有不同芯片做的线卡,很多公司都号称线卡可以混插,但是如果芯片之间差别比较大,要做到混插难度岂不是很大?而且如果表项大小不一,处理起来也很麻烦,只能取最小能力集。对于不同芯片做的数据交换线卡,不知道Cisco,Juniper, Huawei之类是如何处理的?是否他们真的能支持所有不同线卡混插在同一个系统上?
3. 据我了解,做分布式系统架构的时候,Cisco, Huawei, H3C都是把芯片的SDK和底层的适配层放在线卡上,而芯片无关的东西放在主控上,但是据说也有厂家是把包括SDK在内的绝大多数逻辑都放在主控上,线卡上只存放table/register读写接口,所有的计算都在主控完成,线卡只是执行主控的写芯片操作?不知道大家了解的情况是怎么样的?我觉得后面那种方案问题很多,比如无法支持线卡混插,比较难做线卡热插拔,主控压力很大,无法支持分布式转发(即部分软转发决定在线卡上做出)
诸位牛人,请不吝赐教,真的比较困惑,担心是大厂家虚假宣传,挖好了一个大坑让其它厂家往下跳,其实他们也做不到,如果真的那样,我们也不需要担心自己做不到那么完美了。
个打分, 平均:
工具箱I am not sure where to start to explain this one.
I have a list view with a couple image butto on each row. When you click the list row, it launches a new activity. If you review some of my other posts, I have had to build my own ta because of an i ue w/ the camera layout. The activity that gets launched for result is a map. If I click on my button to launch the image preview (load an image off the sd card) the a lication retur from the activity back to the listview activity to the result handler to relaunch my new activity which is nothing more than an image widget.
So here is the i ue, the image preview on the list view is being done w/ the cursor &am listadapter. This makes it pretty simple, but I am not sure how I can put a resized (i.e. smaller bit size not pixel) image as the src for the imgbutton on the fly. So I just resized the image that came off the phone camera.
The i ue is that I get an out of memory error when it tries to go back and re-launch the 2nd activity.
** My question : is there a way I can build the list adapter easily row by row, where I can resize on the fly (bit wise)? - this would be preferable as I also need to make some changes to the properties of the widgets/elements in each row as I am unable to select a row w/ touch screen b/c of focus i ue. (I can use roller ball).
** I know I can do an out of band resize and save of my image, but that is not really what I want to do, but some sample code for that would be nice if that is your suggestion.
As soon as I disabled the image on the listview it worked fine again.
FYI : This is how I was doing it :
String[] from = new String[] { DBHelper.KEY_BUSINESSNAME, DBHelper.KEY_ADDRESS, DBHelper.KEY_CITY, DBHelper.KEY_GPSLONG, DBHelper.KEY_GPSLAT,
DBHelper.KEY_IMAGEFILENAME
to = new int[] { R.id.busine ame, R.id.addre , R.id.city, R.id.g long, R.id.g lat, R.id.imagefilename };
notes =
new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
Where R.id.imagefilename is a ButtonImage
Here is my LogCat
01-25 05:05:49.877: ERROR/dalvikvm-heap(3896): 6291456-byte external allocation too large for this proce .
01-25 05:05:49.877: ERROR/(3896): VM won't let us allocate 6291456 bytes
01-25 05:05:49.877: ERROR/AndroidRuntime(3896): Uncaught handler: thread main exiting due to uncaught exception
01-25 05:05:49.917: ERROR/AndroidRuntime(3896): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:304)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:149)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:174)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.graphics.drawable.Drawable.createFromPath(Drawable.java:729)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.ImageView.resolveUri(ImageView.java:484)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.ImageView.setImageURI(ImageView.java:281)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.SimpleCursorAdapter.setViewImage(SimpleCursorAdapter.java:183)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:129)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.CursorAdapter.getView(CursorAdapter.java:150)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.A ListView.obtainView(A ListView.java:1057)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.ListView.makeAndAddView(ListView.java:1616)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.ListView.fillSpecific(ListView.java:1177)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.ListView.layoutChildren(ListView.java:1454)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.A ListView.onLayout(A ListView.java:937)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.view.View.layout(View.java:5611)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1108)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.LinearLayout.onLayout(LinearLayout.java:922)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.view.View.layout(View.java:5611)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.FrameLayout.onLayout(FrameLayout.java:294)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.view.View.layout(View.java:5611)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:999)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.LinearLayout.onLayout(LinearLayout.java:920)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.view.View.layout(View.java:5611)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.widget.FrameLayout.onLayout(FrameLayout.java:294)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.view.View.layout(View.java:5611)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.view.ViewRoot.performTraversals(ViewRoot.java:771)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.view.ViewRoot.handleMe age(ViewRoot.java:1103)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.os.Handler.di atchMe age(Handler.java:88)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.os.Looper.loop(Looper.java:123)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at android.a .ActivityThread.main(ActivityThread.java:3742)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at java.lang.reflect.Method.invokeNative(Native Method)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at java.lang.reflect.Method.invoke(Method.java:515)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
01-25 05:05:49.917: ERROR/AndroidRuntime(3896):
at dalvik.system.NativeStart.main(Native Method)
01-25 05:10:01.127: ERROR/AndroidRuntime(3943): ERROR: thread attach failed
I also have a new error when di laying an image :
01-25 22:13:18.594: DEBUG/skia(4204): xxxxxxxxxxx jpeg error 20 Improper call to JPEG library in state %d
01-25 22:13:18.604: INFO/System.out(4204): resolveUri failed on bad bitmap uri:
01-25 22:13:18.694: ERROR/dalvikvm-heap(4204): 6291456-byte external allocation too large for this proce .
01-25 22:13:18.694: ERROR/(4204): VM won't let us allocate 6291456 bytes
01-25 22:13:18.694: DEBUG/skia(4204): xxxxxxxxxxxxxxxxxxxx allocPixelRef failed
Jan 25 '09 at 11:23
100% accept rate
1 I put the log in a code block to give it scroll bars dash Jan 25 '09 at 11:51
feedback
protected
Mar 2 at 18:50
This question is protected to prevent "thanks!", "me too!", or am a wers by new users. To a wer it, you must have more than 10
14 A wers
accepted
May be the a wer mentioned on
might solve the i ue...
BitmapFactory.Optio optio = new BitmapFactory.Optio ();
optio .inTempStorage = new byte[16*1024];
bitmapImage = BitmapFactory.decodeFile(path,opt);
a wered
Jul 19 '10 at 10:20
Tried this solution. Unfortunately no effect. Still OutOfMemory for large photos. dash Jul 27 '10 at 0:39
1 I also tried this and still get an OutOfMemory exception too. dash Sep 4 '10 at 22:36
4 I do #39;t think this hel , and the reason I do #39;t is because I read the source code for decodeFile and the source code does this itself if you do #39;t. dash Sep 8 '10 at 13:34
1 didnt, worked for me ! dash Jan 20 at 22:37
1 I tried that, and this a roach is not working. dash Feb 18 at 10:05
feedback
To fix OutOfMemory you should do something like that:
BitmapFactory.Optio optio =new BitmapFactory.Optio ();
optio .inSampleSize = 8;
Bitmap preview_bitmap=BitmapFactory.decodeStream(is,null,optio );
This inSampleSize option reduces memory co umption.
Here's a complete method. First it reads image size without decoding the content itself. Then it finds the best inSampleSize value, it should be a power of 2. And finally the image is decoded.
//decodes image and scales it to reduce memory co umption
private Bitmap decodeFile(File f){
//Decode image size
BitmapFactory.Optio o = new BitmapFactory.Optio ();
o.inJustDecodeBounds = true;
BitmapFactory.decodeStream(new FileI utStream(f),null,o);
//The new size we want to scale to
final int REQUIRED_SIZE=70;
//Find the correct scale value. It should be the power of 2.
int width_tmp=o.outWidth, height_tmp=o.outHeight;
int scale=1;
while(true){
if(width_tmp/2REQUIRED_SIZE || height_tmp/2REQUIRED_SIZE)
width_tmp/=2;
height_tmp/=2;
scale*=2;
//Decode with inSampleSize
BitmapFactory.Optio o2 = new BitmapFactory.Optio ();
o2.inSampleSize=scale;
return BitmapFactory.decodeStream(new FileI utStream(f), null, o2);
} catch (FileNotFoundException e) {}
return null;
a wered
May 5 '09 at 9:00
4 Note that 10 may not be the best value for inSampleSize though, the documentation suggests using powers of 2. dash May 28 '10 at 11:59
3 I love you, Fedor!!! dash May 30 '10 at 22:33
1 I'm facing the same problem as Chri ix, but I do #39;t think the solution here really solves the problem, but rather sideste it.
Changing the sample size reduces the amount of memory used (at the cost of image quality, which is probably okay for an image preview), but it will not prevent the exception if a large enough image stream is decoded, of if multiple image streams are decoded.
If I find a better solution (and there may not be one) I'll post an a wer here. dash Jul 8 '10 at 15:19
1 You only need an a ropriate size to match the screen in pixel de ity, for zooming in and such you can take a sample of the image at a higher de ity. dash Aug 8 '10 at 22:43
1 i tead of scale++ you should use scale *= 2; dash Nov 10 '10 at 10:44
feedback
I've made a small improvement to Fedor's code. It basically does the same, but without the (in my opinion) ugly while loop and it always results in a power of two. Kudos to Fedor for making the original solution, I was stuck until I found his, and then I was able to make this one :)
private Bitmap decodeFile(File f){
Bitmap b = null;
//Decode image size
BitmapFactory.Optio o = new BitmapFactory.Optio ();
o.inJustDecodeBounds = true;
FileI utStream fis = new FileI utStream(f);
BitmapFactory.decodeStream(fis, null, o);
fis.close();
int scale = 1;
if (o.outHeight IMAGE_MAX_SIZE || o.outWidth IMAGE_MAX_SIZE) {
scale = Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
//Decode with inSampleSize
BitmapFactory.Optio o2 = new BitmapFactory.Optio ();
o2.inSampleSize = scale;
fis = new FileI utStream(f);
b = BitmapFactory.decodeStream(fis, null, o2);
fis.close();
} catch (FileNotFoundException e) {
return }
a wered
Aug 23 '10 at 15:25
4 Yes you're right while is not so beautiful. I just tried to make it clear to everyone. Thanks for your code. dash Aug 24 '10 at 1:32
1 This (and Fedor' code) helped point me in the right direction. Thanks! dash Sep 23 '10 at 13:38
3 @Thomas Vervest - There' a big problem with that code.
^ doe #39;t raise 2 to a power, it xors 2 with the result.
You want Math.pow(2.0, ...).
Otherwise, this looks good. dash Oct 13 '10 at 7:42
1 Ooh, that' a very good one! My bad, I'll correct it immediately, thanks for the reply! dash Oct 26 '10 at 9:20
1 You are creating two new FileI utStreams, one for each call to the
BitmapFactory.decodeStream()
. Do #39;t you have to save a reference to each of them so that they can be closed in a
finally
block? dash Feb 15 at 8:21
feedback
You are most likely suffering from this Android bug:
The bug report contai a testcase.
a wered
Aug 8 '10 at 18:13
1 It has been declined :( dash Nov 12 '10 at 9:17
feedback
I have a much more effective solution which does not need scaling of any sort. Simply decode your bitmap only once and then cache it in a map agai t its name. Then simply retrieve the bitmap agai t the name and set it in the ImageView. There is nothing more that needs to be done.
This will work because the actual binary data of the decoded bitmap is not stored within the dalvik VM heap. It is stored externally. So every time you decode a bitmap, it allocates memory outside of VM heap which is never reclaimed by GC
To help you better a reciate this, imagine you have kept ur image in the drawable folder. You just get the image by doing a getResources().getDrwable(R.drawable.). This will NOT decode your image everytime but re-use an already decoded i tance everytime you call it. So in e ence it is cached.
Now since your image is in a file somewhere (or may even be coming from an external server), it is YOUR re o ibility to cache the decoded bitmap i tance to be reused any where it is needed.
Hope this hel .
a wered
Mar 2 at 18:17
and then cache it in a map agai t its name. How exactly do you cache your images? dash Apr 27 at 15:38
Have you actually tried this? Even though the pixel data is not actually stored within the Dalvik heap, its size in native memory is reported to the VM and counted agai t its available memory. dash Jun 10 at 19:45
@Vincent
I think its not hard to store them in a Map. I would suggest something like HashMa lt;KEY, Bitma gt; map, where the Key can be a String of the source or anything that makes se e for you. Lets a ume you take a path as KEY, you store it as map.put(Path, Bitmap) and recieve it through map.get(Path) dash Jun 29 at 11:58
you prob would want to use HashMa lt;String, SoftReferenceBitma gt gt; if you are implementing an image Cache otherwise you may run out of memory anyway - also i dont think that it allocates memory outside of VM heap which is never reclaimed by GC is true, the memory is reclaimed as i understand just may be a delay, which is what bitmap.recycle() is for, as a hint to reclaim the mem early... dash Jul 1 at 8:54
feedback
in Gallery's
public View getView(int position, View convertView, ViewGroup parent) method
how to use
bitmap.recylce();?
this is my code:
ImageView imageview = new ImageView(mContext);
Log.d(TAG, " ImageAdapter
getView
create imageview");
BitmapFactory.Optio optio =new Optio ();
optio .inSampleSize=2;
// mImageIds[position] 如果为空 则给出一个默认图片
Log.e(TAG, "pathlist size num:"+(pathlist.size()==0)+"");
Log.d(TAG, "File path:"+PATH+pathlist.get(mImageIds[position%mImageIds.length]));
File file=new File(PATH+pathlist.get(mImageIds[position%mImageIds.length]));
boolean flag=file.isFile();
Log.d(TAG, "is File :"+flag); =BitmapFactory.decodeFile(PATH+pathlist.get(mImageIds[position%mImageIds.length]),optio );
Log.d(TAG, " ImageAdapter
getView
create bitmap hashcode:"+ .hashCode());
// 给ImageView设置资源
imageview.setImageBitmap( );
Log.d(TAG, " ImageAdapter
getView
set setImageBitmap( )");
// 设置布局 图片120×120显示
imageview.setLayoutParams(new Gallery.LayoutParams(200, 200));
Log.d(TAG, " ImageAdapter
getView
set setLayoutParams(new Gallery.LayoutParams(200, 200))");
// 设置显示比例类型
imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);
} catch (Exception e) {
Log.e(TAG, "e:"+e.getMe age());
e.printStackTrace();
Log.d(TAG, " ImageAdapter
getView
imageview.setScaleType(ImageView.ScaleType.FIT_CENTER):"+ImageView.ScaleType.FIT_CENTER);
return imageview;
a wered
Jan 14 at 2:02
feedback
Its a known bug (
), its not because of large files. Since Android Caches the Drawables, its going out of memory after using few images. But i found alternate way for it, by ski ing the android default cache system.
Soultion
Move the images to "a ets" folder and use the following function to get BitmapDrawable
public static Drawable getA etImage(Context context, String filename) throws IOException {
A etManager a ets = context.getResources().getA ets();
I utStream buffer = new BufferedI utStream((a ets.open("drawable/" + filename + ". g")));
Bitmap bitmap = BitmapFactory.decodeStream(buffer);
return new BitmapDrawable(bitmap);
a wered
May 24 at 20:17
feedback
I did the following to take the image and resize it on the fly. Hope this hel Bitmap bm;
bm = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(filepath),100, 100, true);
mPicture = new ImageView(context);
mPicture.setImageBitmap(bm);
a wered
Feb 16 '09 at 6:23
4 This a roach scales the bitmap. But it doe #39;t solve the OutOfMemory i ue because the full bitmap is being decoded anyway. dash Jan 5 '10 at 6:51
I will see if I can look at my old code, but I think it did solve my out of memory i ues. Will double check my old code. dash Sep 22 '10 at 17:19
feedback
u should first clear all the view...
than u can try...
mea bcz of mobile memory is limited...
bitmap object co umes more memory compare to other.
i had getting the same problem
but after removing all previously created view it worked correctly ...
Enjoy....
a wered
Apr 14 '10 at 9:39
feedback
Hey Sam,
Your problem is probably because of the scale value. It should always be a power of two, if you use my code it should solve your problem :)
a wered
Aug 23 '10 at 15:29
feedback
There are two i ues here....
Bitmap memory i 't in the VM heap but rather in the native heap - see
Garbage collection for the native heap is lazier than the VM heap - so you need to be quite aggre ive about doing bitmap.recycle and bitmap =null every time you go through an Activity's onPause or onDestroy
a wered
May 12 at 4:40
feedback
It seems that this is a very long ru ing problem, with a lot of differing explanatio .
I took the advice of the two most common presented a wers here, but neither one of these solved my problems of the VM claiming it couldn't afford the bytes to perform the
decoding
part of the proce .
After some digging I learned that the real problem here is the decoding proce taking away from the
See here:
That lead me to another discu ion thread where I found a couple more solutio to this problem.
One is to call
System.gc();
manually after your image is di layed.
But that actually makes your a use MORE memory, in an effort to reduce the native heap.
The better solution as of the release of 2.0 (Donut) is to use the BitmapFactory option "inPurgeable".
So I simply added
o2.inPurgeable=true;
just after
o2.inSampleSize=scale;
More on that topic here:
Now, having said all of this, I am a complete dunce with Java and Android too.
So if you think this is a terrible way to solve this problem, you are probably right.
But this has worked wonders for me, and I have found it impo ible to run the VM out of heap cache now.
The only drawback I can find is that you are trashing your cached drawn image.
Which mea if you go RIGHT back to that image, you are redrawing it each and every time.
In the case of how my a lication works, that is not really a problem.
Your mileage may vary.
a wered
May 19 at 16:49
feedback
I have resolved the same i ue in the following ma er.
Bitmap b = null;
Drawable d;
ImageView i = new ImageView(mContext);
b = Bitmap.createBitmap(320,424,Bitmap.Config.RGB_565);
b.eraseColor(0xFFFFFFFF);
Rect r = new Rect(0, 0,320 , 424);
Canvas c = new Canvas(b);
Paint p = new Paint();
p.setColor(0xFFC0C0C0);
c.drawRect(r, p);
d = mContext.getResources().getDrawable(mImageIds[position]);
d.setBounds(r);
d.draw(c);
BitmapFactory.Optio o2 = new BitmapFactory.Optio ();
o2.inTempStorage = new byte[128*1024];
b = BitmapFactory.decodeStream(mContext.getResources().openRawResource(mImageIds[position]), null, o2);
o2.inSampleSize=16;
o2.inPurgeable = true;*/
catch (Exception e){}
i.setImageBitmap(b);
a wered
Jun 4 at 9:44
feedback
Use this bitmap.recylce(); Its solve the problem 100%. Without any image quality i ue.
Regards,
Arsalan A ari
a wered
Nov 7 '10 at 11:08
feedback
Not the a wer you're looking for?
Browse other questio tagged
Hello World!
This is a collaboratively edited question and a wer site for
profe ional and enthusiast programmers
. It's 100% free, no registration required. tagged &time 83448 &time 11462 &time 4565 &time 2261 &time 1245
2 years ago
52,642 times
Get the
weekly newsletter!
Top questio and a wers
Important a ouncements
Una wered questio see an
Related
default
■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ rev 2011.7.27.1
site design / logo 2011 stack exchange inc;
user contributio lice ed under
Stack Overflow works best with JavaScript enabledMy users can change the Locale within the a (they may want to keep their phone settings in English but read the content of my a in French, Dutch or any other language ...)
Why is this working perfectly fine in 1.5/1.6 but NOT in 2.0 anymore ???
@Override
public boolean onOptio ItemSelected(MenuItem item) {
switch(item.getItemId()){
case 201:
Locale locale2 = new Locale("fr");
Locale.setDefault(locale2);
Configuration config2 = new Configuration();
config2.locale = locale2;
getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDi layMetrics());
// loading data ...
refresh();
// refresh the ta and their content
refresh_Tab ();
case 201: etc...
The problem is that the MENU "shrinks" more and more everytime the user is going through the lines of code above ...
This is the Menu that gets shrunk:
@Override
public boolean onCreateOptio Menu(Menu menu) {
menu.add(0, 100, 1, "REFRESH").setIcon(android.R.drawable.ic_menu_compa );
SubMenu langMenu = menu.addSubMenu(0, 200, 2, "NL-FR").setIcon(android.R.drawable.ic_menu_rotate);
langMenu.add(1, 201, 0, "Nederlands");
langMenu.add(1, 202, 0, "Franais");
menu.add(0, 250, 4, R.string.OptionMenu2).setIcon(android.R.drawable.ic_menu_send);
menu.add(0, 300, 5, R.string.OptionMenu3).setIcon(android.R.drawable.ic_menu_preferences);
menu.add(0, 350, 3, R.string.OptionMenu4).setIcon(android.R.drawable.ic_menu_more);
menu.add(0, 400, 6, "Exit").setIcon(android.R.drawable.ic_menu_delete);
return super.onCreateOptio Menu(menu);
What should I do in API Level 5 to make this work again ?
HERE IS THE FULL CODE IF YOU WANT TO TEST THIS :
import java.util.Locale;
import android.a .Activity;
import android.content.res.Configuratio import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
import android.widget.Toast;
public cla Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedI tanceState) {
super.onCreate(savedI tanceState);
setContentView(R.layout.main);
@Override
public boolean onCreateOptio Menu(Menu menu) {
SubMenu langMenu = menu.addSubMenu(0, 200, 2, "NL-FR").setIcon(android.R.drawable.ic_menu_rotate);
langMenu.add(1, 201, 0, "Nederlands");
langMenu.add(1, 202, 0, "Franais");
return super.onCreateOptio Menu(menu);
@Override
public boolean onOptio ItemSelected(MenuItem item) {
switch(item.getItemId()){
case 201:
Locale locale = new Locale("nl");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDi layMetrics());
Toast.makeText(this, "Locale in Nederlands !", Toast.LENGTH_LONG).show();
case 202:
Locale locale2 = new Locale("fr");
Locale.setDefault(locale2);
Configuration config2 = new Configuration();
config2.locale = locale2;
getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDi layMetrics());
Toast.makeText(this, "Locale en Franais !", Toast.LENGTH_LONG).show();
return super.onOptio ItemSelected(item);
AND HERE IS THE MANIFEST :
?xml version="1.0" encoding="utf-8"?
manifest xml :android="http://schemas.android.com/apk/res/android"
package="com.cousinHub.ChangeLocale"
android:versionCode="1"
android:versionName="1.0"
a lication android:icon="@drawable/icon" android:label="@string/a _name"
activity android:name=".Main"
android:label="@string/a _name"
intent-filter
action android:name="android.intent.action.MAIN" /
category android:name="android.intent.category.LAUNCHER" /
/intent-filter
/activity
/a licatio gt;
uses-sdk android:minSdkVersion="3" /
/manifest
THIS IS WHAT I FOUND :
uses-sdk android:minSdkVersion="5" /
=> IT WORKS JUST FINE ...
uses-sdk android:minSdkVersion="3" /
=> Menu shrinks every time you change the locale !!!
as I want to keep my a lication acce ible for users on 1.5, what should I do ??
Feb 15 '10 at 9:13
75% accept rate
What do you mean by ? dash Feb 15 '10 at 13:20
it gets smaller and smaller each time. should I maybe use something else than getBaseContext ? dash Feb 15 '10 at 17:05
Maybe it' not these lines creating the problem as when I do a very basic a doing just the change in Locale, I do #39;t have the same
" hrinking of the menu. I thought it was maybe because my Activity was in fact a TabActivity, but even with that, I ca #39;t re-create the problem. I'll have to investigate further what is the exact cause of this bug... do #39;t search further then. I'll post the a wer here when I find it. Cheers, H. dash Feb 15 '10 at 18:18
I edited my first post, giving an exemple on how to create the problem. And I noticed in fact that when I change the line uses-sdk android:minSdkVersion=5 / to 3 ... indeed the problem a ears ! dash Feb 15 '10 at 18:43
feedback
protected
♦
Nov 22 '10 at 13:00
This question is protected to prevent "thanks!", "me too!", or am a wers by new users. To a wer it, you must have more than 10
4 A wers
accepted
After a good night of leep, I found the a wer on the Web
(a simple Google search on the following line "
getBaseContext().getResources().updateConfiguration(mConfig, getBaseContext().getResources().getDi layMetrics());
"), here it is :
=> this link also shows
scree hots
of what is ha ening !
De ity was the i ue here
I needed to have this in the AndroidManifest.xml
< u orts-scree android:smallScree ="true"
android:normalScree ="true"
android:largeScree ="true"
android:anyDe ity="true"
The most important is the
android:anyDe ity =" true "
Don't forget to add the following in the
manifest
(for every activity) :
android:configChanges="locale"
a wered
Feb 16 '10 at 7:05
1 I had android:anyDe ity=false due to the advice of Google (Strategies for Legacy A licatio - point 9 :
). Be carefull then ! dash Feb 16 '10 at 7:08
feedback
Through the original question is not exactly about the locale itself all other locale related questio are referencing to this one. That's why I wanted to clarify the i ue here. I used this question as a starting point for my own locale switching code and found out that the method is not exactly correct. It works, but only until any configuration change (e.g. screen rotation) and only in that particular Activity. Playing with a code for a while I have ended up with the following a roach:
I have extended android.a .A lication and added the following code:
public cla MyA lication extends A lication
private Locale locale = null;
@Override
public void onConfigurationChanged(Configuration newConfig)
super.onConfigurationChanged(newConfig);
if (locale != null)
newConfig.locale = locale;
Locale.setDefault(locale);
getBaseContext().getResources().updateConfiguration(newConfig, getBaseContext().getResources().getDi layMetrics());
@Override
public void onCreate()
super.onCreate();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
Configuration config = getBaseContext().getResources().getConfiguration();
String lang = settings.getString(getString(R.string.pref_locale), "");
if (! "".equals(lang) &am am ! config.locale.getLanguage().equals(lang))
locale = new Locale(lang);
Locale.setDefault(locale);
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDi layMetrics());
This code e ures that every Activity will have custom locale set and it will not be reset on rotation and other events.
I have also ent a lot of time trying to make the preference change to be a lied immediately but didn't succeed: the language changed correctly on Activity restart, but number formats and other locale properties were not a lied until full a lication restart.
a wered
Nov 21 '10 at 19:02
Is you preference activity being called from you main activity? you could place this in the on resume...
@Override
protected void onResume() {
if (!(PreferenceManager.getDefaultSharedPreferences(
getA licationContext()).getString(listLanguage, e quot;)
.equals(langPreference))) {
refresh();
super.onResume();
private void refresh() {
finish();
Intent myIntent = new Intent(Main.this, Main.cla );
startAct