Friday 18 April 2014

Clear android Layout Cache Memory programitically

 
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
  >
  </RelativeLayout>

 Main.javafile make method like below

RelativeLayout   mRelativeLayoutClearView = (RelativeLayout)findViewById(R.id.root);

 private void unbindDrawables(View view)
    {
        if (view.getBackground() != null)
        {
            view.getBackground().setCallback(null);
        }
        try
        {
            ((ViewGroup) view).removeAllViews();   
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }

    }

Then in Ondestroy Method

    @Override
    protected void onDestroy()

    {
        super.onDestroy();
        System.gc();
        unbindDrawables(mRelativeLayoutClearView);

    }