文章

顯示從 11月, 2022 起發佈的文章

Send Log file when app crashed by runtime exception

     Although we have tested your app before releasing to others or the public, there still are hidden bugs that cause running exceptions we did not catch. Eventually, the app crashed. We want to know what has happened and try to fix it. Therefore, we need the app to send the log file from the installed device to us.  Below is an example to send the log file stored in app-specific storage to a dedicated email address when the app crashed by the runtime exception.      For the method of saving log messages into files, please check the previous post Logging in Android . Create a subclass of Application class to catch the unknown runtime exception      Application class is the first class to be invoked before any other class when the app starts because it is the base class of maintaining global application state. Our purpose is to add a concrete class of Thread.UncaughtExceptionHandler when the app starts.       The inte...

Logging in Android

       While developing an Android app, we often call the method of Log class (Log.d(), Log.i()...) to display the message or parameter that isn’t shown on screen for debugging or confirming the intermediate result. However, the message or parameter is only output to the window of Android Studio. If we ask our friend who is not a developer to test the app, it may be hard for him/her to tell us what the problem is without the log message. One solution is that the app saves the log message into a file on the runtime and then sends back the log file to us when a problem happens.       Logback is one of the logging tools to save the log message into file. Then we can retrieve the file later for analysis. The android version of Logback is Logback-android .

Android RecyclerView with OnClick Event

  Using RecyclerView is preferred over ListView to display lists. Unlike ListView, we do not add the OnItemClickListener directly to RecyclerView. Instead, we set onClickListener inside the ViewHolder. ViewHolder interprets the layout xml file, which may contain multiple UI components. Therefore, we can implement onClickListener to the ViewHolder only implement onClickListener to an individual component in the ViewHolder

Change Locale in runtime

  Android supports multi-language. During Android apps development, we put the locale-specific text in different String.xml files. Android apps will load the corresponding text defined in String.xml according to the system locale setting at startup. However, in some case, we may want to switch the locale in the app differently to the system setting. We can change the Locale in Activity or Fragment.