java - How to getActivity() in a static method? -



java - How to getActivity() in a static method? -

i phone call method1 class, how can utilize getactivity() in static method? found examples fragmentactivity or other types. sorry if question got answered somewhere else, not find implement in code. help appreciated.

public class tab1 extends fragment { public static string readfromfilekurs(context ctx) { ret = ""; seek { inputstream inputstream = ctx.openfileinput("configkurs.txt"); if ( inputstream != null ) { inputstreamreader inputstreamreader = new inputstreamreader(inputstream); bufferedreader bufferedreader = new bufferedreader(inputstreamreader); string receivestring = ""; stringbuilder stringbuilder = new stringbuilder(); while ( (receivestring = bufferedreader.readline()) != null ) { stringbuilder.append(receivestring); } inputstream.close(); ret = stringbuilder.tostring(); } } grab (filenotfoundexception e) { log.e("login activity", "file not found: " + e.tostring()); } grab (ioexception e) { log.e("login activity", "can not read file: " + e.tostring()); } homecoming ret; } public static void method1(){ temp = readfromfile(getactivity()); } }

you can't utilize getactivity(), since it's static method , can't access activity/fragment's methods. may want pass activity parameter (since method1 must called non-static method).

however in case, don't need specific activity - context, context - application context may suffice. refer this question more info.

java android-activity fragment

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -