Is my fragment usage correct, seems to be slow on adnroid
Posted
by
Robertoq
on Stack Overflow
See other posts from Stack Overflow
or by Robertoq
Published on 2012-10-29T10:58:35Z
Indexed on
2012/10/29
11:00 UTC
Read the original article
Hit count: 310
My app structure is that i have a menu with 5 menu-point om the left side, and the content on the right side.
MainActivity.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/fragmentMenu"
android:name="com.example.FragmentMenu"
android:layout_width="@dimen/MenuWidth"
android:layout_height="match_parent" />
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android_layout_toRightOf="@+id/fragmentMenu"
android:orientation="vertical"/>
</RelativeLayout>
MainActivity.java
public class FragmentActivityMain extends FragmentActivity {
@Override
protected void onCreate(final Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.fragment_activity_main);
FragmentManager fm = getSupportFragmentManager();
FragmentMenu fragmentMenu = (FragmentMenu) fm.findFragmentById(R.id.fragmentMenu);
fragmentMenu.init();
}
}
And certainly I have a FragmenMenu class,
public class FragmentMenu extends ListFragment {
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_menu, container, false);
return view;
}
public init() {
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
FragmentNowListView lw = new FragmentCarListView();
ft.add(R.id.content, lw);
ft.commit();
}
}
The FragmentCarList is a simple list, now with static test data, only five items in a List
My Problem: Slow. I tested the app on my phone (Galaxy S3) and I see white screen when app starting, around 0,5 second and this is the log:
- 10-29 11:43:44.093: D/dalvikvm(29710): GC_CONCURRENT freed 267K, 5% free 13903K/14535K, paused 10ms+2ms
- 10-29 11:43:44.133: D/dalvikvm(29710): GC_FOR_ALLOC freed 215K, 6% free 13896K/14663K, paused 12ms
- 10-29 11:43:44.233: D/dalvikvm(29710): GC_FOR_ALLOC freed 262K, 6% free 13901K/14663K, paused 12ms
- 10-29 11:43:44.258: D/dalvikvm(29710): GC_FOR_ALLOC freed 212K, 6% free 13897K/14663K, paused 13ms
- 10-29 11:43:44.278: D/dalvikvm(29710): GC_FOR_ALLOC freed 208K, 6% free 13897K/14663K, paused 12ms
- 10-29 11:43:44.328: D/dalvikvm(29710): GC_FOR_ALLOC freed 131K, 4% free 14098K/14663K, paused 12ms
- 10-29 11:43:44.398: D/dalvikvm(29710): GC_CONCURRENT freed 20K, 3% free 14559K/14919K, paused 1ms+4ms
And when I tested on Xperia Ray, the whit screen appear longer time.
How can I optimize my fragments? Thx
© Stack Overflow or respective owner