如何显示最近的活动?

时间:2013-04-08 07:26:50

标签: java android

我在Android演示中创建了4个活动。当我的问题    从我的第一个活动运行应用程序以显示第二个活动    我正试图让数据保持原样    按下应用程序退出的3活动中的后退按钮但是    当我回到第三个活动和数据时,我重新启动    保持原样相同。我使用Intent使用共享首选项    但它运作不正常

@Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_screen);



        final SharedPreferences sharedPref=this.getSharedPreferences("MY_PREF_1",MODE_WORLD_READABLE);
        SharedPreferences.Editor shredPref_Editor=sharedPref.edit();
        //shredPref_Editor.putString(MY_ACTIVITY,"splash_activity");
        prefName = sharedPref.getString(MY_ACTIVITY,"splash_activity");

        handler = new Handler(){};

        runnable = new Runnable() {

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

                if(prefName == "splash_activity" || prefName.toString().trim().equals("Number_Activity"))
                {
                    Intent i1=new Intent(Splash_Screen_Activity.this,Number_Activity.class);
                    startActivity(i1);
                }


                else if(prefName.toString().trim().equals("pin_number_activity"))
                {
                    Intent i2=new Intent(Splash_Screen_Activity.this,PIN_Number_Activity.class);
                    startActivity(i2);
                }


                else
                {
                    Intent i3=new Intent(Splash_Screen_Activity.this , Custom_Title_Bar_Activity.class);
                    startActivity(i3);
                }

            }
        };






 public class Number_Activity extends Activity
    {
        private final String MY_ACTIVITY = "Number_Activity";

    public void onCreate(Bundle savedInstanceState)
        {

            super.onCreate(savedInstanceState);
            setContentView(R.layout.cell_number);

            SharedPreferences sharedPref=this.getSharedPreferences("MY_PREF_2",MODE_WORLD_READABLE);
            SharedPreferences.Editor shredPref_Editor=sharedPref.edit();
            shredPref_Editor.putString(MY_ACTIVITY,"number_activity");
            shredPref_Editor.commit();
        }   
    }




public class PIN_Number_Activity extends Activity
{
    private final String MY_ACTIVITY = "PinNum_MyActivity";


         public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pin_number);

        SharedPreferences sharedPref=this.getSharedPreferences("MY_PREF_3",MODE_WORLD_READABLE);
        SharedPreferences.Editor shredPref_Editor=sharedPref.edit();
        shredPref_Editor.putString(MY_ACTIVITY,"pin_number_activity");
        shredPref_Editor.commit();
        }
}





public class Custom_Title_Bar_Activity extends Activity
{
    private final String MY_ACTIVITY = "Main_Activity";


protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Boolean customTitleSupported=requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main_for_ctitlebar);

        SharedPreferences sharedPref=this.getSharedPreferences("MY_PREF_4",MODE_WORLD_READABLE);
        SharedPreferences.Editor shredPref_Editor=sharedPref.edit();
        shredPref_Editor.putString(MY_ACTIVITY,"main_activity");
        shredPref_Editor.commit();

}

}

0 个答案:

没有答案