0

i writed an application which contains an option button and Option Activity. In the OptionActivity, you can choose play a music "on" or "off" with togglebutton. and there are some check button also. until here everything is okey but when you check some box and back to the main menu and back to the Options Activity again, you find that all variables is default value. for example the checked box one is uncheckhed. I know that it is because of everyCall the Options Activity with new Intent but i want to know that starting an activity "without using new Intent"

This is my SPLASH SCREEN

public class MainActivity extends Activity {

/* (non-Javadoc)
 * @see android.app.Activity#onCreate(android.os.Bundle)
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.baslangic);

    Thread thred=new Thread(){
public void run(){
    try {

        sleep(5000);

        startActivity(new Intent("com.KAYA.ingilizce_gelistirme.OPTIONS"));

        startActivity(new Intent("com.KAYA.ingilizce_gelistirme.BASLANGIC"));
    } catch (InterruptedException e) {
        e.printStackTrace();
    }finally{
        finish();

    }
}
};
thred.start();

}

}

This is my MAIN ACTİVTY which contains options button

public class Baslangic extends Activity {

@Override
protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();



}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button start=(Button)findViewById(R.id.button1);
    Button options=(Button)findViewById(R.id.button2);
    Button about=(Button)findViewById(R.id.button3);

     start.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            startActivity(new Intent("com.KAYA.ingilizce_gelistirme.OYUN"));

        }
    });
    options.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();

        }
    });

    about.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent("com.KAYA.ingilizce_gelistirme.ABOUT"));

        }
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

}

And This is My options Activity

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.options);
     it=(RadioButton)findViewById(R.id.radio0);
     ti=(RadioButton)findViewById(R.id.radio1);
     final ToggleButton but=(ToggleButton)findViewById(R.id.toggleButton1);
     music=MediaPlayer.create(Options.this, R.raw.avril);


    but.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if(but.isChecked())
            music.start();
            else
            music.pause();

        }
    });
     it.setChecked(true);
     Button menu=(Button)findViewById(R.id.button1);
     menu.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent("com.KAYA.ingilizce_gelistirme.BASLANGIC"));
        }
    });

}

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub


    startActivity(new Intent("com.KAYA.ingilizce_gelistirme.BASLANGIC"));
    }
@Override
protected void onPause() {

    super.onPause();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
}

@Override
protected void onStop() {
    super.onStop();
}

}

NOTE: Be aware That when the user click the options Button, i call finish(), actually i have a solution. My solution that, after the splash screen, i start 2 activity; first Options later Menu, And when the user click the Options button and i call the finish() so i am in the options Button :D and when press back i called new Intent(menu) you can see on OPTIONS activity, So my problem is already solved but i want to know that there should be a solution different from this way, If you know pls help me. :)

4

1 に答える 1

0

PreferenceActivity または通常の Activity スーパークラスを使用していますか?

とにかく、必ず SharedPreferences について読んでください。アプリ全体または単一のアクティビティの値を保存できます。

于 2013-02-02T00:07:29.427 に答える