This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
how can i create a class and use this piece of code. If i put the code in the fragment class, MODE_WORLD_READABLE cannot be resolved to a variable error is displayed. Only when i add this code to an activity it works.
In general i get a byte array and write it to a file. When this was on the activity class it worked great. When i added it to a fragment class it displays the error above.
MODE_WORLD_READABLE is defined in Context, and Activity is a subclass of Context. But since you move the code out of the Activity, you need to tell the compiler (and Eclipse) where MODE_WORLD_READABLE comes from, so use Context.MODE_WORLD_READABLE instead.