Android 在oncreate之前是否可以接受来自intent的值
为了遵循oop的概念,我对代码进行了分段,因此,出现在四个活动中的代码被制作成一个单独的活动。。现在,这个子活动actions取决于它从四个父活动中的哪一个被调用。。因此,setContent视图值根据父活动的不同而变化Android 在oncreate之前是否可以接受来自intent的值,android,android-intent,Android,Android Intent,为了遵循oop的概念,我对代码进行了分段,因此,出现在四个活动中的代码被制作成一个单独的活动。。现在,这个子活动actions取决于它从四个父活动中的哪一个被调用。。因此,setContent视图值根据父活动的不同而变化 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pdf_view); In
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pdf_view);
Intent intent = getIntent();
String url = intent.getStringExtra("URL");
我明白了
您所要做的就是在setcontent视图方法之前调用on create函数中的intent
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
String url = intent.getStringExtra("URL");
String layout = intent.getStringExtra("layout");
int id =getResourceUsingName(layout,"layout");
setContentView(id);
}
private int getResourceUsingName(String name, String type) {
mContext=getApplicationContext();
Resources resources = mContext.getResources();
int resourceId = resources.getIdentifier(name, type,
mContext.getPackageName());
return resourceId;
}
您应该真正理解活动生命周期,然后重新表述您的问题,因为现在是这样。不清楚您想要什么。@阿尔文我想在调用setContentView之前可以从intent获取值。那会对你有帮助的。你能解释一下吗,你想要这个吗?@Pankaj希望这能解释。。