Skip to content

Commit

Permalink
메모리최적화
Browse files Browse the repository at this point in the history
  • Loading branch information
jangwonseo committed Nov 3, 2015
1 parent 9b5f134 commit 0b7eeab
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 41 deletions.
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<uses-permission android:name="android.permission.WRITE_OWNER_DATA" />
<uses-permission android:name="android.permission.READ_OWNER_DATA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.CALL_PHONE" />

<application
android:name=".sign.MyApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public class HomeActivity extends Activity implements BaseSliderView.OnSliderCli
private LinearLayout slidingPage01;

// 홈에 추천 마을(체험) 이미지
private ImageView webvHomeImage;
private ArrayList<Item> recommendItems = new ArrayList<>();
//ArrayList<Item> recommendItems10 = new ArrayList<>();

Expand All @@ -84,9 +83,6 @@ public class HomeActivity extends Activity implements BaseSliderView.OnSliderCli

private LinearLayout HomeBackGround;
private String userId;
private Button eventButton;

private Typeface yunGothicFont; //윤고딕폰트

//이미지 슬라이더 관련
private SliderLayout mDemoSlider;
Expand Down Expand Up @@ -144,9 +140,6 @@ protected void onCreate(Bundle savedInstanceState) {

sha = new SHA256();

//윤고딕 폰트
yunGothicFont = Typeface.createFromAsset(getAssets(), "fonts/yungothic330.ttf");

//sharedPreference로 전역 공유공간을 만듬
setting = getSharedPreferences("setting", MODE_PRIVATE);
editor = setting.edit();
Expand Down Expand Up @@ -238,30 +231,15 @@ public void onClick(View view) {
// 배경이 하얕게 나오는데 투명하게 만들어줌
webvProfile.setBackgroundColor(0);
webvProfile.setVerticalScrollBarEnabled(false);
//webvProfile.setVerticalScrollbarOverlay(false);
webvProfile.setHorizontalScrollBarEnabled(false);
//webvProfile.setHorizontalScrollbarOverlay(false);
webvProfile.setFocusableInTouchMode(false);
webvProfile.setHorizontalScrollBarEnabled(false);
webvProfile.setVerticalScrollBarEnabled(false);
//webvProfile.setInitialScale(100);
webvProfile.setFocusable(false);

webvProfile.setImageDrawable(null);
new DownloadImageTask(webvProfile).execute("http://218.150.181.131/seo/image/" + userId + "Profile.jpg");
//webvProfile.loadDataWithBaseURL(null, creHtmlBody("http://218.150.181.131/seo/image/" + userId + "Profile.jpg"), "text/html", "utf-8", null);

/*
eventButton = (Button) findViewById(R.id.eventbutton);
eventButton.setTypeface(yunGothicFont);
eventButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), EventWindow.class);
startActivity(intent);
}
});
*/
}

@Override
Expand Down Expand Up @@ -310,11 +288,6 @@ public void onClick(View v) {
@Override
protected void onResume() {
mDemoSlider.startAutoCycle();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
findViewById(R.id.homebackground).setBackground(getResources().getDrawable(R.drawable.home1));
}else{
findViewById(R.id.homebackground).setBackgroundResource(R.drawable.home1);
}
System.gc();
super.onResume();
}
Expand All @@ -323,30 +296,21 @@ protected void onResume() {
protected void onStop() {
// To prevent a memory leak on rotation, make sure to call stopAutoCycle() on the slider before activity or fragment is destroyed
mDemoSlider.stopAutoCycle();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
findViewById(R.id.homebackground).setBackground(null);
}else{
findViewById(R.id.homebackground).setBackgroundResource(R.drawable.home1);
}
System.gc();
super.onStop();
}

@Override
protected void onPause() {
mDemoSlider.stopAutoCycle();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
findViewById(R.id.homebackground).setBackground(null);
}else{
findViewById(R.id.homebackground).setBackgroundResource(R.drawable.home1);
}
System.gc();

super.onPause();
}

@Override
protected void onDestroy() {
Log.d("seojangjang","home destroy");
mDemoSlider.destroyDrawingCache();
mDemoSlider.stopAutoCycle();
recycleBitmap(mDemoSlider);
Expand All @@ -368,6 +332,7 @@ private static void recycleBitmap(SliderLayout iv) {
d = null;
}


@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,8 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon

@Override
protected void onDestroy() {

//Adapter가 있으면 어댑터에서 생성한 recycle메소드를 실행

Log.d("seojangjang","list destroy");
//Adapter가 있으면 어댑터에서 생성한 recycle메소드를 실행
if (adapter != null) {
adapter.recycle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ public void onClick(View v) {

@Override
protected void onDestroy() {
Log.d("seojangjang","listdetail destroy");
adapter = null;
data.clear();
RecycleUtils.recursiveRecycle(getWindow().getDecorView());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package vivz.slidenerd.agriculture.region_theme;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
Expand All @@ -10,6 +13,7 @@
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import vivz.slidenerd.agriculture.R;
Expand Down Expand Up @@ -185,6 +189,16 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

private static void recycleBitmap(ImageView iv) {
Drawable d = iv.getDrawable();
if (d instanceof BitmapDrawable) {
Bitmap b = ((BitmapDrawable)d).getBitmap();
b.recycle();
} // 현재로서는 BitmapDrawable 이외의 drawable 들에 대한 직접적인 메모리 해제는 불가능하다.

d.setCallback(null);
}

@Override
protected void onDestroy() {
RecycleUtils.recursiveRecycle(getWindow().getDecorView());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -121,6 +122,7 @@ public void onClick(View v)

@Override
protected void onDestroy() {
Log.d("seojangjang", "themechoice destroy");
RecycleUtils.recursiveRecycle(getWindow().getDecorView());
System.gc();
super.onDestroy();
Expand Down

0 comments on commit 0b7eeab

Please sign in to comment.