点击ListView item 跳转到另一个Activity 跳转到的Activity 点击 back 执行finish(); 再返回ListView
内存不断升高 .求教大神是什么问题跳转到的Activity 有一张图片. 在xml 设置背景的 文件大概在200k
内存不断升高 .求教大神是什么问题跳转到的Activity 有一张图片. 在xml 设置背景的 文件大概在200k
解决方案 »
- 新年了问个问题,下载android源码时遇到的,求解。
- 编译器上面的问题
- google为选用JAVA来开发android,还存在oracle的官司问题
- android中数据库的操作
- [2012-07-12 15:35:33 - DeviceMonitor] Adb connection Error:远程主机强迫关闭了一个现有的连接。
- android listview求解
- bootanimation 不流畅问题
- 如何用Opencv用数学函数去识辨试管底部
- MotionEvent.ACTION_MOVE 触发事件刷新频率太低
- 彻底逆天了,这样的代码,报这样的错误!
- HashSet
- 大神是怎么练成的?
"Abbaye de Belloc", "Abbaye du Mont des Cats", "Abertam", "Abondance", "Ackawi",
"Acorn", "Adelost", "Affidelice au Chablis", "Afuega'l Pitu", "Airag", "Airedale",
"Aisy Cendre", "Allgauer Emmentaler", "Alverca", "Ambert", "American Cheese",
"Ami du Chambertin", "Anejo Enchilado"
};
firendsListView = (ListView) findViewById(R.id.firendslist);
firendsListView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, mStrings));
firendsListView.setOnItemClickListener(new OnItemClickListener() { @Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Intent intent = new Intent(AddressBookActivity.this,FriendsDataActivity.class);
startActivity(intent);
}
});
FriendsDataActivity back_btn = (CommonButton)findViewById(R.id.back_btn);
back_btn = (CommonButton)findViewById(R.id.back_btn);
back_btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
FriendsDataActivityxml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_common_full"
android:orientation="vertical">
<com.cs.sgs.common.CommonButton
android:layout_gravity="center_vertical"
android:layout_height="wrap_content"
android:id="@+id/back_btn"
android:layout_marginLeft="@dimen/margin_value4"
android:background="@drawable/bar_button_l_normal"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:textSize="@dimen/button_text_size"
android:text="@string/back"
android:gravity="center"
android:textStyle="bold"></com.cs.sgs.common.CommonButton>
<ImageView android:background="@drawable/cs_0000" android:layout_width="wrap_content" android:layout_height="wrap_content">
</ImageView>
</LinearLayout>cs_0000 这张图片大概200k 左右
没有加载数据 没有再执行onCreate 方法
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
Intent intent = new Intent(AddressBookActivity.this,FriendsDataActivity.class);
startActivity(intent);
finish();//或者system.exit(0);
}
这个是listview 没必要 finish();//
我觉得应该是java垃圾回收机制引起的,当然,并不是说这个机制有问题,嗯,举个例子吧,楼主的Intent intent = new Intent(AddressBookActivity.this,FriendsDataActivity.class);这行代码,其实就是实例化了一个Intent,这样做,系统自然会为其分配内存,每点击一次都new一次,相当于实例化不同的对象,自然要占用更多的内存,而java垃圾回收机制是在特定的时间内回收一次,或者内存不足时‘强制’回收,自然存在着回收延迟问题,这样一来, 就有了内存不断升高的‘错觉’。
或许你会觉得,这点内存肯定不会算什么,但是否想过,这样的代码,在android源码里面会有多少?肯定不少吧?
也不是说这样写代码不正确,其实大多数人都是这样写的,只是想说,程序在运行过程中内存攀升是不可避免的(大概,对某些牛人写的程序,这个词可能不适用),不过有java垃圾回收机制在,这种问题引起的内存攀升是不会照成太大的影响的。
当然,如果觉得不放心,也可以手动释放这些资源占用的内存空间,不过这样做的话,安全性就不能保证了,java的有点之一,就是因为他的垃圾回收机制,所以为什么非要纠结这个问题呢?
呃,最后再说一句,以上仅属于个人观点,正确与否不敢保证,毕竟我也看到过很多android应用,运行起来过后,用用内存检测软件来看的话,内存几乎没有变化,也不知道这个内存优化是如何做的,大牛啊