Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. protected void onPause(){
  2. super.onPause();
  3. unbindDrawables(findViewById(R.id.login_root));
  4. }
  5.  
  6. protected void onDestroy() {
  7. unbindDrawables(findViewById(R.id.login_root));
  8. super.onDestroy();
  9. }
  10.  
  11. private void unbindDrawables(View view) {
  12. System.gc();
  13. Runtime.getRuntime().gc();
  14. if (view.getBackground() != null) {
  15. view.getBackground().setCallback(null);
  16. }
  17. if (view instanceof ViewGroup) {
  18. for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
  19. unbindDrawables(((ViewGroup) view).getChildAt(i));
  20. }
  21. ((ViewGroup) view).removeAllViews();
  22. }
  23.  
  24. public void onCreate(Bundle savedInstanceState) {
  25. super.onCreate(savedInstanceState);
  26. }
  27.  
  28. protected void onResume(){
  29. setContentView(R.layout.home);
  30. Bitmap bmp;
  31. ImageView background = (ImageView)findViewById(R.id.iv_home_background);
  32. InputStream is = getResources().openRawResource(R.drawable.background);
  33. bmp = BitmapFactory.decodeStream(is);
  34. background.setImageBitmap(bmp);
  35.  
  36. super.onResume();
  37. }
  38.  
  39. protected void onPause(){
  40. super.onPause();
  41. unbindDrawables(findViewById(R.id.home_root));
  42. }
  43.  
  44.  
  45. private void unbindDrawables(View view) {
  46. System.gc();
  47. Runtime.getRuntime().gc();
  48. if (view.getBackground() != null) {
  49. view.getBackground().setCallback(null);
  50. }
  51. if (view instanceof ViewGroup) {
  52. for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
  53. unbindDrawables(((ViewGroup) view).getChildAt(i));
  54. }
  55. ((ViewGroup) view).removeAllViews();
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement