我正在尝试添加第二个onCreate,但当我这样做时它不起作用,第一个Oncreate
当我按TextView
它完成工作并带我到SecondActivity,但是当我按下第二个调用Oncreate1
时,它不会为我做这个工作并把我带到FirstActivity,即使我做了同样的事情我为Oncreate
我做了不知道问题是什么,希望你能帮助我
这是logcat
12-26 04:13:27.390: I/Ads(1808): Ad url modified to http://googleads.g.doubleclick.net:80/mads/gma?preqs=0&session_id=7802952340037714008&seq_num=1&u_w=384&msid=imamalsajadsayings.android.com&cap=m%2Ca&js=afma-sdk-a-v6.4.1&bas_off=0&net=ed&app_name=3.android.imamalsajadsayings.android.com&hl=en&gnt=3&carrier=310260&u_audio=4&kw&u_sd=2&ms=MMbiAdsTBWDvSdyekwxcU1HfnPY0zVDgymfntXc0HtctkjVkiQVLwpyucG2sYhOjA-oCD3ttwEUCEaLiC7z810qPte8UcMBibTH6mFdmFZpFqMtfE-ZQ-qbdeoxgUiVSgJYqK4bpoDU_WFa3wexgrJAYtMktIhKFa_6IELwlqNqTS157Vrm5Cv-95PJq-kHr-EorriTQzyw0HE_eBM5KrLg2JcAZwS1uXPDGOehjdapmAyJ7FZJ_YTg1Vr85Ux94RIqrdwPvOiLW1BzOFEtNtmMmsb47xAjv-fEYOrG_0DnHIwK-CXcnifK8wHi2RTSkWyNxiIqxPc6RNxvG7GD8Ww&format=320x50_mb&oar=0&u_h=592&bas_on=0&ptime=0&imbf=8008&u_so=p&output=html®ion=mobile_app&u_tz=-300&client_sdk=1&ex=1&slotname=a152b5665edfefd&kw_type=broad&gsb=3g&caps=inlineVideo_interactiveVideo_mraid1_th_autoplay_mediation_sdkAdmobApiForAds_di&jsv=66&urll=909
12-26 04:13:27.390: I/Ads(1808): Request scenario: Online server request.
12-26 04:13:31.650: W/EGL_emulation(1808): eglSurfaceAttrib not implemented
12-26 04:13:31.890: I/Choreographer(1808): Skipped 34 frames! The application may be doing too much work on its main thread.
12-26 04:13:35.060: I/Choreographer(1808): Skipped 75 frames! The application may be doing too much work on its main thread.
12-26 04:13:37.470: W/EGL_emulation(1808): eglSurfaceAttrib not implemented
12-26 04:13:38.380: I/Ads(1808): onReceiveAd()
12-26 04:13:39.140: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000b44
12-26 04:13:39.180: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000bd0
12-26 04:13:39.400: I/chromium(1808): [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported
12-26 04:13:40.010: I/chromium(1808): [INFO:async_pixel_transfer_manager_android.cc(56)] Async pixel transfers not supported
12-26 04:13:40.170: E/eglCodecCommon(1808): **** ERROR unknown type 0x0 (glSizeof,72)
12-26 04:13:40.550: I/Choreographer(1808): Skipped 86 frames! The application may be doing too much work on its main thread.
12-26 04:13:40.590: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000b44
12-26 04:13:40.610: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000bd0
12-26 04:13:40.870: E/eglCodecCommon(1808): **** ERROR unknown type 0x0 (glSizeof,72)
12-26 04:13:41.300: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000b44
12-26 04:13:41.310: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000bd0
12-26 04:13:41.390: E/eglCodecCommon(1808): **** ERROR unknown type 0x0 (glSizeof,72)
12-26 04:13:41.520: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000b44
12-26 04:13:41.560: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000bd0
12-26 04:13:41.740: E/eglCodecCommon(1808): **** ERROR unknown type 0x0 (glSizeof,72)
12-26 04:13:41.830: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000b44
12-26 04:13:41.850: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000bd0
12-26 04:13:41.910: E/eglCodecCommon(1808): **** ERROR unknown type 0x0 (glSizeof,72)
12-26 04:13:42.070: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000b44
12-26 04:13:42.090: E/eglCodecCommon(1808): glUtilsParamSize: unknow param 0x00000bd0
。
这是MainActivity
package imamalsajadsayings.android.com;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView mTextView;
private TextView mTextView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById( R.id.state2 );
mTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,SecondActivity.class);
startActivity(i);
}
});
}
protected void onCreate1(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
mTextView1 = (TextView) findViewById( R.id.state1 );
mTextView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this,FirstActivity.class);
startActivity(i);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items TO the action bar IF it IS present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
我希望你能帮助我让Oncreate1
也有效......
提前致谢
答案 0 :(得分:2)
该方法名为onCreate()
,它将在创建时运行(顾名思义)。如果您创建一个名为onCreate1()
的方法,它将与创建名为neverCallThisMethodAutomatically()
的方法完全相同,即如果您希望它运行,则需要手动调用它。
仅仅因为方法名称类似于onCreate()
并不意味着它会表现得像它一样。
答案 1 :(得分:2)
现在Oncreate1()是你自己的方法,它不能被Activity覆盖,你必须调用Oncreate1()
答案 2 :(得分:2)
我不知道从哪里开始......
我首先要说super.onCreate(savedInstanceState);
中的OnCreate1()
来电可能不是一个好主意。
话虽如此......整个实施都非常错误。请考虑更改为fragments,如果我理解正确的话,它会让您更好。
另请阅读Application Fundamentals,Intents,Activities和Java Inheritance
祝你好运。答案 3 :(得分:0)
使用like并参考Android life cycle,
package imamalsajadsayings.android.com;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView mTextView;
private TextView mTextView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (TextView) findViewById(R.id.state2);
mTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, SecondActivity.class);
startActivity(i);
}
});
mTextView1 = (TextView) findViewById(R.id.state1);
mTextView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, FirstActivity.class);
startActivity(i);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items TO the action bar IF it IS present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}