Reputation: 278
I am trying to access the assets
folder's files from a non-activity class, but I am not able to do it. How do I do it?
Upvotes: 2
Views: 4099
Reputation: 133560
Pass the context to the NonActivity
class
new NonActivity(ActivityName.this);
Then in the constructor
Context mContext;
public NonActivity(Context context)
{
mContext = context;
}
Then use the context as below
InputStream is = mContext.getAssets().open(file_path);
Do not create an instance of Activity class. Activity has a lifecycle and is started by startActivity with intent as param.
Upvotes: 6