我使用這種模式:有什麼辦法可以在Android中自動記錄方法名稱?
public class FooProvider extends ContentProvider {
private static final String TAG = FooProvider.class.getSimpleName();
...
@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
l.v(TAG, TAG + ".update() Uri:" + uri.toString() + " " + db.getPath());
其中L是我的包裝輪機器人會Log.v這需要字符串參數... args。這讓logcat的輸出是這樣的:
FooProvider.update() Uri: foo bar etc
我正在尋找的是一個登錄方法名的方式,在這種情況下更新(),自動在能經受住TAG重構的方式做的方式。我已經看到了class.getMethods()調用,但看不到在運行時用當前方法爲返回列表建立索引的方法。
你應該試試這個簡單的lib:https://github.com/MustafaFerhan/DebugLog – gturedi