The code is followed:
Context c = getContext().createPackageContext("com.master.schedule", Context.CONTEXT_INCLUDE_CODE|Context.CONTEXT_IGNORE_SECURITY);
int id = c.getResources().getIdentifier("layout_main", "layout","com.master.schedule"); LayoutInflater inflater = LayoutInflater.from(c); piflowView = inflater.inflate(id, null);
com.master.schedule
is my package project.The upside code presents how the other project(his package name is different to mine) inflate my project, in my project there is only a ViewGroup(I don't have an activity); and when I invoke "context.getApplicationContext
", it returns null... my project code is below:
public class CascadeLayout extends RelativeLayout {
private Context context;
public CascadeLayout(Context context) {
super(context);
this.context=context.getApplicationContext();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
//here: context == null;
}
}
I find the createPackageContext()
give the "Context c
" to me is a ContextImpl
type; I think that's caused return null;
So how can I get an ApplicationContext which not null?
BTW:please don't persuade me don't invoke getApplicationContext();
As I must use an .jar, the jar need to invoke getApplicationContext()
in it;
thanks very very much.