fshb_ 1370
جمعه 17 شهریور 1391, 10:36 صبح
سلام
من این تکه کد از کتاب Hello Android خوندم و در درکش مشکل دارم. سرچ کردم و خیلی از مشکلاتم حل شد. اما چیزی که هنوز متوجه نشدم:
private void startGame(int i) {
Log.d(TAG, "clicked on " + i);
Intent intent = new Intent(Sudoku.this, Game.class);
intent.putExtra(Game.KEY_DIFFICULTY, i);
startActivity(intent);
}
public class Game extends Activity {
private static final String TAG = "Sudoku" ;
public static final String KEY_DIFFICULTY =
"org.example.sudoku.difficulty" ;
public static final int DIFFICULTY_EASY = 0;
public static final int DIFFICULTY_MEDIUM = 1;
public static final int DIFFICULTY_HARD = 2;
private int puzzle[] = new int[9 * 9];
private PuzzleView puzzleView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate" );
int diff = getIntent().getIntExtra(KEY_DIFFICULTY,
DIFFICULTY_EASY);
puzzle = getPuzzle(diff);
calculateUsedTiles();
puzzleView = new PuzzleView(this);
setContentView(puzzleView);
puzzleView.requestFocus();
}
// ...
}
putExtra() یک value از extra data میحونه؟؟
getIntExtra() یک value در extra data میذاره؟؟
در خط Intent intent = new Intent(Sudoku.this, Game.class); با Game.class ما وارد کلاس Game میشیم و یکی یکی خط ها اجرا میشه. درسته؟
اینا رو لطفا جواب بدین تا سوالات بعدی ;)
مرسی
من این تکه کد از کتاب Hello Android خوندم و در درکش مشکل دارم. سرچ کردم و خیلی از مشکلاتم حل شد. اما چیزی که هنوز متوجه نشدم:
private void startGame(int i) {
Log.d(TAG, "clicked on " + i);
Intent intent = new Intent(Sudoku.this, Game.class);
intent.putExtra(Game.KEY_DIFFICULTY, i);
startActivity(intent);
}
public class Game extends Activity {
private static final String TAG = "Sudoku" ;
public static final String KEY_DIFFICULTY =
"org.example.sudoku.difficulty" ;
public static final int DIFFICULTY_EASY = 0;
public static final int DIFFICULTY_MEDIUM = 1;
public static final int DIFFICULTY_HARD = 2;
private int puzzle[] = new int[9 * 9];
private PuzzleView puzzleView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate" );
int diff = getIntent().getIntExtra(KEY_DIFFICULTY,
DIFFICULTY_EASY);
puzzle = getPuzzle(diff);
calculateUsedTiles();
puzzleView = new PuzzleView(this);
setContentView(puzzleView);
puzzleView.requestFocus();
}
// ...
}
putExtra() یک value از extra data میحونه؟؟
getIntExtra() یک value در extra data میذاره؟؟
در خط Intent intent = new Intent(Sudoku.this, Game.class); با Game.class ما وارد کلاس Game میشیم و یکی یکی خط ها اجرا میشه. درسته؟
اینا رو لطفا جواب بدین تا سوالات بعدی ;)
مرسی