私のエミュレータの向きを変更するときに私はいくつかの本当に奇妙な問題があります。私のアプリでは、画像ボタンをクリックすると、メインアクティビティから「設定」という名前のアクティビティを呼び出します。ここではそのためのコードは次のとおりです。ここでAndroidの変更奇妙な問題
final ImageButton stbtn = (ImageButton) findViewById(R.id.stbtn);
stbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent stopn = new Intent(MyApp.this, Settings.class);
startActivity(stopn);
}
});
は、私が設定アクティビティを閉じる方法です:
@Override
public void onBackPressed() {
// do something on back.
finish();
return;
}
@Override
protected void onPause(){
super.onPause();
saveSettings();
}
と私のメインの活動に私が表面その更新画面を毎秒を表示しています。私は、設定を変更するために設定画面に行き、戻るボタンを押してそれを閉じて、これは正常に動作するメインの活動画面に行く。問題は、アプリがメイン画面にあるときに方向を変更すると、設定アクティビティが戻ることです。それは私がアクティビティを閉じていないか、それとも何か他のものですか?誰もがこれで私を助けてくれる?おかげ
編集:
public class MyAlarm extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getClockSettings();
HandView hndView = (HandView) findViewById(R.id.hndView);
clkapp = ((myappApp)getApplicationContext());
hndView.setStyle(clkapp.getClkStyle(), clkapp.isAnalog());
final ImageButton alrbtn = (ImageButton) findViewById(R.id.alrbtn);
alrbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
}
});
final ImageButton stbtn = (ImageButton) findViewById(R.id.stbtn);
stbtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent stopn = new Intent(MyAlarm.this, Settings.class);
//stopn.setClassName("com.example.myapp", "com.example.myapp.Settings");
startActivity(stopn);
}
});
stbtn.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.requestFocusFromTouch();
Intent stopn = new Intent(MyAlarm.this, Settings.class);
//stopn.setClassName("com.example.myapp", "com.example.myapp.Settings");
startActivity(stopn);
return true;
}
});
}
protected void getClockSettings() {
//getting setting from preferences
clkSettings = getSharedPreferences(PREFS_NAME, 0);
if (clkapp == null) clkapp = ((myappApp)getApplicationContext());
clkapp.clkSettings = clkSettings;
if (clkSettings == null) {
/*clk24 = false;
clkAnalogue = true;
dSec = true;
_clockStyle = "Black";*/
clkapp.set24Hr(false);
clkapp.setAnalog(true);
clkapp.setDisplaySec(true);
clkapp.setClkStyle("Black");
}
else {
/*clk24 = clkSettings.getBoolean("24Hr", false);
dSec = clkSettings.getBoolean("dSecond", true);
clkAnalogue = clkSettings.getBoolean("ClkAnalogue", true);
if (clkAnalogue) _clockStyle = clkSettings.getString("ClkAnalogStyle", "Black");
else _clockStyle = clkSettings.getString("ClkAnalogStyle", "DigitalBlack");*/
clkapp.set24Hr(clkSettings.getBoolean("24Hr", false));
clkapp.setAnalog(clkSettings.getBoolean("ClkAnalogue", true));
clkapp.setDisplaySec(clkSettings.getBoolean("dSecond", true));
if (clkapp.isAnalog()) clkapp.setClkStyle(clkSettings.getString("ClkAnalogStyle", "Black"));
else clkapp.setClkStyle(clkSettings.getString("ClkAnalogStyle", "DigitalBlack"));
}
}
public void onConfigurationChanged(Configuration newConfig) {
//ignore orientation change
super.onConfigurationChanged(newConfig);
}
}
セッティングアクティビティ:
public class Settings extends Activity {
//Your member variable declaration here
private RadioButton crbon;
private RadioButton blue;
private RadioButton bbl;
private RadioButton crbdig;
private RadioButton grndig;
private ToggleButton tb24;
private ToggleButton tbsec;
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
//Your code here
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
myappApp clkapp = ((myappApp)getApplicationContext());
//RadioGroup rbgrp = (RadioGroup)findViewById(R.id.rbfacegrp);
crbon=(RadioButton)findViewById(R.id.radio_carbon);
blue=(RadioButton)findViewById(R.id.radio_blue);
bbl=(RadioButton)findViewById(R.id.radio_bbl);
crbdig=(RadioButton)findViewById(R.id.radio_crbdig);
grndig=(RadioButton)findViewById(R.id.radio_grndig);
tb24=(ToggleButton)findViewById(R.id.tbhr);
tbsec=(ToggleButton)findViewById(R.id.tbsec);
if(clkapp.getClkStyle().toLowerCase().equals("black")) {
crbon.setChecked(true);
}
else if(clkapp.getClkStyle().toLowerCase().equals("blue")) {
blue.setChecked(true);
}
else if(clkapp.getClkStyle().toLowerCase().equals("bubble")) {
bbl.setChecked(true);
}
else if(clkapp.getClkStyle().toLowerCase().equals("digitalblack")) {
crbdig.setChecked(true);
}
else if(clkapp.getClkStyle().toLowerCase().equals("digitalgreen")) {
grndig.setChecked(true);
}
tb24.setChecked(clkapp.is24Hr());
tbsec.setChecked(clkapp.isDisplaySec());
}
@Override
protected void onPause(){
super.onPause();
saveSettings();
//this.finish();
}
protected void saveSettings() {
boolean clkAna = true;
myappApp clkapp = ((myappApp)getApplicationContext());
SharedPreferences.Editor edt = clkapp.clkSettings.edit();
edt.putBoolean("24Hr", tb24.isChecked());
edt.putBoolean("dSecond", tbsec.isChecked());
clkapp.set24Hr(tb24.isChecked());
clkapp.setDisplaySec(tbsec.isChecked());
if (crbon.isChecked()) {
edt.putString("ClkAnalogStyle", "Black");
clkapp.setClkStyle("Black");
clkAna = true;
}
else if (blue.isChecked()) {
edt.putString("ClkAnalogStyle", "Blue");
clkapp.setClkStyle("Blue");
clkAna = true;
}
else if (bbl.isChecked()) {
edt.putString("ClkAnalogStyle", "Bubble");
clkapp.setClkStyle("Bubble");
clkAna = true;
}
else if (crbdig.isChecked()) {
edt.putString("ClkAnalogStyle", "DigitalBlack");
clkapp.setClkStyle("DigitalBlack");
clkAna = false;
}
else if (grndig.isChecked()) {
edt.putString("ClkAnalogStyle", "DigitalGreen");
clkapp.setClkStyle("DigitalGreen");
clkAna = false;
}
clkapp.setAnalog(clkAna);
edt.putBoolean("ClkAnalogue", clkAna);
edt.commit();
}
@Override
public void onBackPressed() {
// do something on back.
finish();
return;
}
}
活動の状態を元に戻すの典型的なよくある質問のようにそれは聞こえない - Parashar @回転が実際に設定アクティビティ...起こるべきではありません開始していることを言っているに存在する場合、事実、2つの異なる活動。 – Cheezmeister
うん、それは@Cheezmeister、ちょうど私の問題thats私はそれを引き起こしていることを把握することはできませんそれを得た。私には2つの異なる活動があります。私はオリエンテーション変更の前にそれを閉じても、設定アクティビティが再び表示される理由を理解していません – Parashar
十分に公正です。両方のアクティビティとマニフェストを投稿すると、問題が見えるかどうかがわかります。私はまだ症状を修正するための明示的な変更を期待しています。それは? –