我有意图问题。我在主要活动中使用它并调用另一个活动但是再次单击其调用主要活动。这是我的代码
主要活动.java
package com.umair.facebook;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
ImageView img1;
TextView txt, txt3;
Button like, share, update;
EditText et1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img1 = (ImageView) findViewById(R.id.img);
txt = (TextView) findViewById(R.id.name);
txt3 = (TextView) findViewById(R.id.status);
like = (Button) findViewById(R.id.Like);
share = (Button) findViewById(R.id.Share);
update = (Button) findViewById(R.id.Comment);
et1 = (EditText) findViewById(R.id.editText1);
like.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
// TODO Auto-generated method stub
like.setText("Liked");
}
});
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
share.setText("Shared");
}
});
update.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub startGame();
}
});
}
private void startGame() {
// TODO Auto-generated method stub
Intent lanuchGame = new Intent(MainActivity.this, Result.class);
startActivity(lanuchGame);
}
}
Result.java(第二个活动)
package com.umair.facebook;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class Result extends MainActivity {
ImageView img;
TextView txt1, txt2;
Button btn1, btn2,btn3;
EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
setContentView(R.layout.result_1);
super.onCreate(savedInstanceState);
img =(ImageView)findViewById(R.id.img1);
txt1= (TextView)findViewById(R.id.nam);
txt2= (TextView)findViewById(R.id.stats);
btn1=(Button)findViewById(R.id.Liked);
btn2=(Button)findViewById(R.id.Shared);
et=(EditText)findViewById(R.id.editText); } }
答案 0 :(得分:2)
在第二个super.onCreate(savedInstanceState)
中 setContentView()
之前致电Activity
。