简体   繁体   English

如何读取应用中的完整日志?

[英]How to read full logs in an apliction?

I have multiple activities in my app. 我的应用程序中有多个活动。 I want to read all logs in txt file. 我想读取txt文件中的所有日志。 I have used this link Save logs in file in onCreate() of one activity. 我已使用此链接将日志保存到一个活动的onCreate() 文件中。 I am getting only logs of that activty in which i have written code of read logs. 我只得到其中已编写读取日志代码的活动日志。 Now I want to read all logs in all activities. 现在,我想阅读所有活动中的所有日志。

Thanks 谢谢

You can create one BaseActivity and extend this BaseActivity to all the activities. 您可以创建一个BaseActivity并将此BaseActivity扩展到所有活动。

Now you can write some important code in BaseActivity which can be helpful in all the Activities. 现在,您可以在BaseActivity编写一些重要的代码,这对所有Activity都有帮助。 This way you don't need to write similar code in All the activities and it will create Base Structure for your project which can be useful to you in future. 这样,您无需在所有活动中都编写类似的代码,它将为您的项目创建基础结构,将来对您很有用。

Or 要么

You can write one method in Utils class and call that method from every activities, by this way you need to create method only once, but have to call from every activities when needed. 您可以在Utils类中编写一个方法,然后从每个活动中调用该方法,通过这种方式,您只需创建一次方法,但是在需要时必须从每个活动中调用。

eg 例如

//Creating method in util class
public class Utils{
    public static void addLog(String params, ...){
    /* Your code goes here... */
    }
}

//calling from activities
Utils.addLog(params...);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM