M.ds M.ds - 2 months ago 4
Android Question

An Error With Using Log.i()

I'm trying to use a service in android studio(2.1.2) and I need to use Log.i() , but I have this error :The logging tag can be at most 23 characters. now I don't know how can I fix it !.

Here are my codes:

package com.example.n5110.intent;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class MyService extends Service {

private static final String TAG ="com.example.n5110.intent";
public MyService() {
}


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(TAG,"onStartCommand called");

Runnable r = new Runnable() {
@Override
public void run() {
for(int i = 0; i<5; i++){
long futureTime = System.currentTimeMillis()+ 5000;
while (System.currentTimeMillis() < futureTime){
synchronized (this){
try{
wait(futureTime - System.currentTimeMillis());
Log.i(TAG,"Service is busy");
}catch (Exception e){}
}
}
}
}
};
Thread buckysThread = new Thread(r);
buckysThread.start();
return Service.START_STICKY;
}

@Override
public void onDestroy() {
Log.i(TAG,"onDestroy called");
}

@Override
public IBinder onBind(Intent intent) {
return null;
}
}


Does anyone have any idea??

Answer

Just make your tag shorter. Do you really need this tag in logs?

private static final String TAG ="MyService: ";

This should be enough

Comments