保存一堆活动

时间:2014-07-15 10:59:25

标签: android

让我们说:我有活动A,我去活动B.然后用主页按钮进入主屏幕。我恢复了应用程序。现在我有相同的活动B.这是我的问题:如果我想回到活动A,我按回按钮,我被迫进入主屏幕。我想我应该以某种方式保存一堆活动。更有经验的人可以指路吗?

抱歉我的英文。我试图清楚地解释我的问题。这是B活动

public class RouteActivity extends ActionBar {
    Button find;
    EditText myLocation;
    EditText ObjLoc1;
    EditText ObjLoc2 ;
    EditText ObjLoc3;
    public void onCreate(Bundle savedInstanceState) {

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

        final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );

        if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
            Intent gpsOptionsIntent = new Intent(  
                    android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);  
                startActivity(gpsOptionsIntent);
        }

        getActionBar().setDisplayHomeAsUpEnabled(true);
        Intent intent = getIntent(); // gaunam
        User user = (User) intent.getSerializableExtra("user");

        myLocation = (EditText) findViewById(R.id.routeCurrentLocation);
        ObjLoc1 = (EditText) findViewById(R.id.routeObjectAddress1);
        ObjLoc2 = (EditText) findViewById(R.id.routeObjectAddress2);
        ObjLoc3 = (EditText) findViewById(R.id.routeObjectAddress3);

        find = (Button) findViewById(R.id.routeSubmit);
        find.setOnClickListener(new View.OnClickListener() {

            @SuppressLint("ShowToast")
            @Override
            public void onClick(View v) {

                dosig();

            }
        });
    }

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

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

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

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



}

我像这样开始我的RouteActivity

                    Intent menuIntent = new Intent(
                            "com.project.my.RouteActivity");
                    menuIntent.putExtra("link", realLink);
                    menuIntent.putExtra("user", user);
                    startActivity(menuIntent);

1 个答案:

答案 0 :(得分:0)

要返回您的A活动,您可以在B活动中听取主页按钮按下并完成B活动

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_HOME:
      {
        B.this.finish();
        return false;
      }
    }
}

return super.onKeyDown(keyCode, event);
}