diff --git a/app/src/main/java/com/zxy/tiny/test/BaseActivity.java b/app/src/main/java/com/zxy/tiny/test/BaseActivity.java index 9dc5169..fad1ac7 100644 --- a/app/src/main/java/com/zxy/tiny/test/BaseActivity.java +++ b/app/src/main/java/com/zxy/tiny/test/BaseActivity.java @@ -15,8 +15,7 @@ public class BaseActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState, PersistableBundle persistentState) { super.onCreate(savedInstanceState, persistentState); - Runtime.getRuntime().gc(); - + gcAndFinalize(); } void startActivity(Class clazz) { @@ -26,6 +25,13 @@ void startActivity(Class clazz) { @Override protected void onDestroy() { super.onDestroy(); - Runtime.getRuntime().gc(); + gcAndFinalize(); + } + + void gcAndFinalize() { + Runtime runtime = Runtime.getRuntime(); + System.gc(); + runtime.runFinalization(); + System.gc(); } } diff --git a/app/src/main/java/com/zxy/tiny/test/BatchBitmapCompressTestActivity.java b/app/src/main/java/com/zxy/tiny/test/BatchBitmapCompressTestActivity.java index 132ce7c..dbabfef 100644 --- a/app/src/main/java/com/zxy/tiny/test/BatchBitmapCompressTestActivity.java +++ b/app/src/main/java/com/zxy/tiny/test/BatchBitmapCompressTestActivity.java @@ -4,7 +4,6 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; import android.text.format.Formatter; import android.view.Menu; import android.view.MenuItem; @@ -83,47 +82,23 @@ public boolean onOptionsItemSelected(MenuItem item) { break; case R.id.action_file: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testFile(); - } - }, 500); + gcAndFinalize(); + testFile(); break; case R.id.action_bitmap: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testBitmap(); - } - }, 500); + gcAndFinalize(); + testBitmap(); break; case R.id.action_res: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testResource(); - } - }, 500); + gcAndFinalize(); + testResource(); break; case R.id.action_uri: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testUri(); - } - }, 500); + gcAndFinalize(); + testUri(); break; default: break; diff --git a/app/src/main/java/com/zxy/tiny/test/BatchFileCompressTestActivity.java b/app/src/main/java/com/zxy/tiny/test/BatchFileCompressTestActivity.java index b5db2b5..8b36197 100644 --- a/app/src/main/java/com/zxy/tiny/test/BatchFileCompressTestActivity.java +++ b/app/src/main/java/com/zxy/tiny/test/BatchFileCompressTestActivity.java @@ -4,8 +4,6 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; -import android.support.v7.app.AppCompatActivity; import android.text.format.Formatter; import android.view.Menu; import android.view.MenuItem; @@ -19,7 +17,7 @@ import java.io.FileOutputStream; import java.io.InputStream; -public class BatchFileCompressTestActivity extends AppCompatActivity { +public class BatchFileCompressTestActivity extends BaseActivity { private ImageView mOriginImg1; @@ -83,47 +81,23 @@ public boolean onOptionsItemSelected(MenuItem item) { break; case R.id.action_file: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testFile(); - } - }, 500); + gcAndFinalize(); + testFile(); break; case R.id.action_bitmap: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testBitmap(); - } - }, 500); + gcAndFinalize(); + testBitmap(); break; case R.id.action_res: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testResource(); - } - }, 500); + gcAndFinalize(); + testResource(); break; case R.id.action_uri: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testUri(); - } - }, 500); + gcAndFinalize(); + testUri(); break; default: break; diff --git a/app/src/main/java/com/zxy/tiny/test/BatchFileWithReturnBitmapCompressTestActivity.java b/app/src/main/java/com/zxy/tiny/test/BatchFileWithReturnBitmapCompressTestActivity.java index c749266..d8f5c9b 100644 --- a/app/src/main/java/com/zxy/tiny/test/BatchFileWithReturnBitmapCompressTestActivity.java +++ b/app/src/main/java/com/zxy/tiny/test/BatchFileWithReturnBitmapCompressTestActivity.java @@ -4,8 +4,6 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; -import android.support.v7.app.AppCompatActivity; import android.text.format.Formatter; import android.view.Menu; import android.view.MenuItem; @@ -19,7 +17,7 @@ import java.io.FileOutputStream; import java.io.InputStream; -public class BatchFileWithReturnBitmapCompressTestActivity extends AppCompatActivity { +public class BatchFileWithReturnBitmapCompressTestActivity extends BaseActivity { private ImageView mOriginImg1; @@ -83,47 +81,23 @@ public boolean onOptionsItemSelected(MenuItem item) { break; case R.id.action_file: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testFile(); - } - }, 500); + gcAndFinalize(); + testFile(); break; case R.id.action_bitmap: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testBitmap(); - } - }, 500); + gcAndFinalize(); + testBitmap(); break; case R.id.action_res: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testResource(); - } - }, 500); + gcAndFinalize(); + testResource(); break; case R.id.action_uri: free(); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testUri(); - } - }, 500); + gcAndFinalize(); + testUri(); break; default: break; diff --git a/app/src/main/java/com/zxy/tiny/test/BitmapCompressTestActivity.java b/app/src/main/java/com/zxy/tiny/test/BitmapCompressTestActivity.java index cffba1f..a1405a4 100644 --- a/app/src/main/java/com/zxy/tiny/test/BitmapCompressTestActivity.java +++ b/app/src/main/java/com/zxy/tiny/test/BitmapCompressTestActivity.java @@ -4,7 +4,6 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; import android.text.format.Formatter; import android.view.Menu; import android.view.MenuItem; @@ -55,7 +54,8 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); - + mOriginImg.setImageBitmap(null); + mCompressImg.setImageBitmap(null); switch (id) { case R.id.action_config: if (mConfig == Bitmap.Config.ARGB_8888) { @@ -68,77 +68,29 @@ public boolean onOptionsItemSelected(MenuItem item) { break; case R.id.action_bytes: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); //free memory for test - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testBytes(); - } - }, 500); + gcAndFinalize(); + testBytes(); break; case R.id.action_file: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testFile(); - } - }, 500); + gcAndFinalize(); + testFile(); break; case R.id.action_bitmap: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testBitmap(); - } - }, 500); + gcAndFinalize(); + testBitmap(); break; case R.id.action_stream: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testStream(); - } - }, 500); + gcAndFinalize(); + testStream(); break; case R.id.action_res: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testResource(); - } - }, 500); + gcAndFinalize(); + testResource(); break; case R.id.action_uri: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testUri(); - } - }, 500); + gcAndFinalize(); + testUri(); break; default: break; diff --git a/app/src/main/java/com/zxy/tiny/test/FileCompressTestActivity.java b/app/src/main/java/com/zxy/tiny/test/FileCompressTestActivity.java index a6c73c5..94d0eee 100644 --- a/app/src/main/java/com/zxy/tiny/test/FileCompressTestActivity.java +++ b/app/src/main/java/com/zxy/tiny/test/FileCompressTestActivity.java @@ -4,7 +4,6 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; import android.text.format.Formatter; import android.view.Menu; import android.view.MenuItem; @@ -52,7 +51,7 @@ public boolean onCreateOptionsMenu(Menu menu) { @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); - + mOriginImg.setImageBitmap(null); switch (id) { case R.id.action_config: if (mConfig == Bitmap.Config.ARGB_8888) { @@ -65,71 +64,29 @@ public boolean onOptionsItemSelected(MenuItem item) { break; case R.id.action_bytes: - mOriginImg.setImageBitmap(null); //free memory for test - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testBytes(); - } - }, 500); + gcAndFinalize(); + testBytes(); break; case R.id.action_file: - mOriginImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testFile(); - } - }, 500); + gcAndFinalize(); + testFile(); break; case R.id.action_bitmap: - mOriginImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testBitmap(); - } - }, 500); + gcAndFinalize(); + testBitmap(); break; case R.id.action_stream: - mOriginImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testStream(); - } - }, 500); + gcAndFinalize(); + testStream(); break; case R.id.action_res: - mOriginImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testResource(); - } - }, 500); + gcAndFinalize(); + testResource(); break; case R.id.action_uri: - mOriginImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testUri(); - } - }, 500); + gcAndFinalize(); + testUri(); break; default: break; diff --git a/app/src/main/java/com/zxy/tiny/test/FileWithReturnBitmapCompressTestActivity.java b/app/src/main/java/com/zxy/tiny/test/FileWithReturnBitmapCompressTestActivity.java index c55b858..a3d01f8 100644 --- a/app/src/main/java/com/zxy/tiny/test/FileWithReturnBitmapCompressTestActivity.java +++ b/app/src/main/java/com/zxy/tiny/test/FileWithReturnBitmapCompressTestActivity.java @@ -4,7 +4,6 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Bundle; -import android.os.Handler; import android.text.format.Formatter; import android.view.Menu; import android.view.MenuItem; @@ -69,76 +68,29 @@ public boolean onOptionsItemSelected(MenuItem item) { break; case R.id.action_bytes: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testBytes(); - } - }, 500); + //free memory for test + gcAndFinalize(); + testBytes(); break; case R.id.action_file: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testFile(); - } - }, 500); + gcAndFinalize(); + testFile(); break; case R.id.action_bitmap: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testBitmap(); - } - }, 500); + gcAndFinalize(); + testBitmap(); break; case R.id.action_stream: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testStream(); - } - }, 500); + gcAndFinalize(); + testStream(); break; case R.id.action_res: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testResource(); - } - }, 500); + gcAndFinalize(); + testResource(); break; case R.id.action_uri: - mOriginImg.setImageBitmap(null); - mCompressImg.setImageBitmap(null); - Runtime.getRuntime().gc(); - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - Runtime.getRuntime().gc(); - testUri(); - } - }, 500); + gcAndFinalize(); + testUri(); break; default: break; diff --git a/tiny/build.gradle b/tiny/build.gradle index fe881de..4f6e8f2 100644 --- a/tiny/build.gradle +++ b/tiny/build.gradle @@ -31,7 +31,7 @@ dependencies { ext { upload_group_id = 'com.zxy.android' - upload_version = TINY_VERSION + upload_version = '0.0.1' site_url = 'https://github.com/Sunzxyong/Tiny' git_url = 'https://github.com/Sunzxyong/Tiny.git'