package com.example.tictactoemain;
import com.example.tictactoelib.GameActivity;
import com.example.tictactoelib.GameView.State;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import com.example.tictactoelib.GameActivity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
private void startGame(boolean startWithHuman) {
Intent i = new Intent(this, GameActivity.class);
i.putExtra(GameActivity.EXTRA_START_PLAYER, startWithHuman ? State.PLAYER1.getValue() : State.PLAYER2.getValue());
startActivity(i);
}
}
GameActivity:
package com.example.tictactoelib;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import com.example.tictactoelib.GameView.State;
public class GameActivity extends Activity {
public static final String EXTRA_START_PLAYER =
"com.example.android.tictactoelib.GameActivity.EXTRA_START_PLAYER";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@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;
}
}
在MainActivity内部我收到错误:
EXTRA_START_PLAYER cannot be resolved or is not a field.
主项目将tictactoelib引用为带有绿色复选框的库。 tictactoelib也是作为图书馆项目创建的。尽管EXTRA_START_PLAYER被定义为公共静态最终字符串,但主项目似乎没有看到它。我正在拼凑TicTacToe SDK android-17项目,所以我试图解决错误,虽然我还不知道问题出在哪里。
我也想知道:="com.example.android.tictactoelib.GameActivity.EXTRA_START_PLAYER";
提前致谢...
答案 0 :(得分:0)
使用
private void startGame(boolean startWithHuman) {
Intent i = new Intent(this, GameActivity.class);
i.putExtra("com.example.android.tictactoelib.GameActivity.EXTRA_START_PLAYER", startWithHuman ? State.PLAYER1.getValue() : State.PLAYER2.getValue());
startActivity(i);
}
相反,如果您只在一个活动中使用它