I got the following method in the non Activity class, my code is below.
public class ReadTextByLineNo { public void setContext(Context _context) { if (context == null) { context = _context; } } public String getTextByLine(int Filename,int LineNumber) { String output=""; String line=""; int counter=1; try { InputStream in = context.getResources().openRawResource(Filename);
** I am calling this method from the NON_ACTIVITY LIKE THIS class **
class sample implements Isample { ReadTextByLineNo read = new ReadTextByLineNo(); String subMsg = read.getTextByLine(R.raw.subtitle, storySceneId);
How to use resources / context from non-activity class? I cannot use context in the constructor, since I also call a method from the non Activity class. so i cant set read.setContent (this); where I got the setContext method in my ReadtextByLineNo class, thanks for the help.
Please help me get the context / resource in the sample class and example using code.
source share