Logcat during production

I used my own class, which is responsible for logging with the following implementation

public class Logger {

     public final static boolean DEBUG = true;

     public static void d(String tag, String msg) {
         if(DEBUG)
             Log.d(tag, msg);
     }

} 

When I free the application, I set the flag to false, however it was said that the following method is not as efficient as Stringsit is still allocated and then freed in memory

logger used:

Logger.d("tag", "message");

or maybe so by doing this StringBuilderwill be called

Logger.d("tag", "server response: " + response + " timing: " + timing);

It is true that the dalvik / compiler cannot optimize it to prevent this behavior. and if so, is there anything I can do to optimize it, other than moving the if outward?

+4
source share
2 answers

Proguard, - apk. "proguarding".

:.

: ?

, , ( ), :)

+1

, String Activity , :

public class YourActivity extends Activity
{
    String tag;
    String message;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        // Rest of Activity

, , /:

tag = "myTag";
message = "myMessage";
Logger.d(tag, message);

, if Logger .

0

All Articles