General methods of Android activity base class

Source: Internet
Author: User

  1. Public class Baseactivity extends Activity {
  2. Resources Res; //generic resource abbreviation
  3. @Override
  4. protected void OnCreate (Bundle savedinstancestate) {
  5. Requestwindowfeature (Window.feature_no_title); //Do not show title
  6. super.oncreate (savedinstancestate);
  7. res = getresources (); //generic resource abbreviation
  8. //optimize IME mode
  9. int inputmode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN;
  10. GetWindow (). Setsoftinputmode (Inputmode);
  11. }
  12. /** 
  13. * Check whether the string is an empty object or an empty string
  14. *
  15. * @param str
  16. * @return is NULL returns TRUE, NOT NULL returns false
  17. */
  18. Public boolean isNull (String str) {
  19. if (null = = STR | | "". Equals (str) | | "null". Equalsignorecase (str)) {  
  20. return true;
  21. } Else {
  22. return false;
  23. }
  24. }
  25. /** 
  26. * Check if string is string
  27. *
  28. * @param str
  29. * @return is NULL returns TRUE, NOT NULL returns false
  30. */
  31. Public boolean isstr (String str) {
  32. return!isnull (str);
  33. }
  34. /** 
  35. * Jump from Current activity to target activity,<br>
  36. * If the target activity has been opened, re-display,<br>
  37. * If you have never opened, create a new open
  38. *
  39. * @param CLS
  40. */
  41. public void Gotoexistactivity (class<?> cls) {
  42. Intent Intent;
  43. Intent = New Intent (this, CLS);
  44. Intent.addflags (Intent.flag_activity_reorder_to_front);
  45. StartActivity (Intent);
  46. }
  47. /** 
  48. * Create a new activity open
  49. *
  50. * @param CLS
  51. */
  52. public void Gotoactivity (class<?> cls) {
  53. Intent Intent;
  54. Intent = New Intent (this, CLS);
  55. StartActivity (Intent);
  56. }
  57. /** 
  58. * Generic message hint
  59. *
  60. * @param resId
  61. */
  62. public void toast (int resId) {
  63. Toast.maketext (This, ResId, Toast.length_short). Show ();
  64. }
  65. /** 
  66. * Generic message hint
  67. *
  68. * @param resId
  69. */
  70. public void Toast (String msg) {
  71. Toast.maketext (This, MSG, Toast.length_short). Show ();
  72. }
  73. /** 
  74. * Get string from resource
  75. *
  76. * @param resId
  77. * @return
  78. */
  79. Public String getstr (int resId) {
  80. return res.getstring (resId);
  81. }
  82. /** 
  83. * Get string from EditText
  84. *
  85. * @param editText
  86. * @return
  87. */
  88. Public String getstr (EditText EditText) {
  89. return Edittext.gettext (). toString ();
  90. }
  91. @Override
  92. Public boolean onKeyDown (int keycode, keyevent event) {
  93. switch (keycode) {
  94. Case Keyevent.keycode_back:
  95. This.finish ();
  96. }
  97. return Super.onkeydown (KeyCode, event);
  98. }
  99. }

General methods of Android activity base class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.