0

I have multiple activities in my app. I want to read all logs in txt file. I have used this link Save logs in file in onCreate() of one activity. 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

1 Answers1

1

You can create one BaseActivity and extend this BaseActivity to all the activities.

Now you can write some important code in BaseActivity which can be helpful in all the Activities. 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.

e.g.

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

//calling from activities
Utils.addLog(params...);
Pragnesh Ghoda シ
  • 8,318
  • 3
  • 25
  • 40
  • I have tried your solution but I am reading only first time logs that means if I perform any event it will not write logs on after event occur. – user8269038 Nov 23 '17 at 06:18
  • Suppose I have call `addLog()` in `onCreate()`, it will write logs till `onCreate()` after that it will not write other logs. – user8269038 Nov 23 '17 at 06:23
  • You have to specify the events at particular time of event when it performs. You can call Utils method when event performs and log will be entered in your file. But make sure you don't override content in file. Try to append your data if file is already available. – Pragnesh Ghoda シ Nov 23 '17 at 06:23
  • that means I have to call method every time where I have written logs. is it better solution? – user8269038 Nov 23 '17 at 06:24
  • If you write `addLog()` in `onCreate()` of `BaseActivity`, that means it will log all the events in `onCreate` which extends `BaseActivity` – Pragnesh Ghoda シ Nov 23 '17 at 06:27
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/159635/discussion-between-user8269038-and-prags-). – user8269038 Nov 23 '17 at 06:27