如何在android中支持以前的活动

如何在android中支持以前的活动,android,android-intent,android-activity,Android,Android Intent,Android Activity,我有3项活动:A、B和C 在甲级, Intent i = new Intent(getApplicationContext(),B.class); i.putExtra("id", user); startActivity(i); 在B班 String u = getIntent().getStringExtra("id"); ---- bla bla bla --- Intent i = new Intent(getApplicationContext(),C.class); i.pu

我有3项活动:A、B和C

在甲级,

Intent i = new Intent(getApplicationContext(),B.class);
i.putExtra("id", user);
startActivity(i);
在B班

String u = getIntent().getStringExtra("id");

 ---- bla bla bla ---

Intent i = new Intent(getApplicationContext(),C.class);
i.putExtra("name", name);
i.putExtra("tel",tel);
startActivity(i);
现在我在“活动C”。如何回到“活动B”?我正在尝试place finish(),但出现错误“不幸的是,APPNAME已停止”。背景为“活动A”

我想回到“B活动”。
请帮助我。

您可以使用
onBackPressed()返回到上一个活动的方法

在活动C的layput上放置一个按钮,并将此
置于backpressed()在按钮上单击侦听器。。就像下面

btn_back.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        onBackPressed();
    }
});
这可能会帮助您..

尝试使用,可以通过在清单文件的
活动
元素中放置一个属性
android:parentActivityName
(在案例B中需要设置为您的父活动)并调用
setDisplayHomeAsUpEnabled()
在活动的onCreate方法中。

阅读以下内容

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
         {

    Intent intent = new Intent(getActivity(), Activitya.class);
    intent.putExtra("position", position);

    intent.putExtra("id", gallery.getGalId());
    intent.putExtra("name", gallery.getAlbumTitle());
    startActivity(intent);

    }
然后像这样做:

例如:

public class Activitya extends FragmentActivity {

    @Override

       protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.your_activity);
       position = getIntent().getExtras().getInt("position");

       id = getIntent().getExtras().getString("id");

       name = getIntent().getExtras().getString("name");
       final ActionBar actionBar = getActionBar();

       getActionBar().setDisplayHomeAsUpEnabled(true);

       }

    @Override
        public boolean onOptionsItemSelected(MenuItem item) { 
        switch (item.getItemId()) {
        case android.R.id.home: 
        onBackPressed();
        return true;
        }

       return super.onOptionsItemSelected(item);
        }
      }
活动A:

public class Activitya extends FragmentActivity {

    @Override

       protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.your_activity);
       position = getIntent().getExtras().getInt("position");

       id = getIntent().getExtras().getString("id");

       name = getIntent().getExtras().getString("name");
       final ActionBar actionBar = getActionBar();

       getActionBar().setDisplayHomeAsUpEnabled(true);

       }

    @Override
        public boolean onOptionsItemSelected(MenuItem item) { 
        switch (item.getItemId()) {
        case android.R.id.home: 
        onBackPressed();
        return true;
        }

       return super.onOptionsItemSelected(item);
        }
      }
活动B:

public class Activitya extends FragmentActivity {

    @Override

       protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.your_activity);
       position = getIntent().getExtras().getInt("position");

       id = getIntent().getExtras().getString("id");

       name = getIntent().getExtras().getString("name");
       final ActionBar actionBar = getActionBar();

       getActionBar().setDisplayHomeAsUpEnabled(true);

       }

    @Override
        public boolean onOptionsItemSelected(MenuItem item) { 
        switch (item.getItemId()) {
        case android.R.id.home: 
        onBackPressed();
        return true;
        }

       return super.onOptionsItemSelected(item);
        }
      }
在活动B中,您必须使用
意图
返回到上一个活动

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
         {

    Intent intent = new Intent(getActivity(), Activitya.class);
    intent.putExtra("position", position);

    intent.putExtra("id", gallery.getGalId());
    intent.putExtra("name", gallery.getAlbumTitle());
    startActivity(intent);

    }
@覆盖
公共视图单击(AdapterView arg0、视图arg1、整型arg2、长型arg3)
{
Intent Intent=新的Intent(getActivity(),Activitya.class);
意图。额外(“位置”,位置);
intent.putExtra(“id”,gallery.getGalId());
intent.putExtra(“name”,gallery.getAlbumTitle());
星触觉(意向);
}

请添加完整的Logcat Logcat非常有用,完全可以帮助您。。在这里输入logcat试试backpressed()方法或finish(),我认为您是从C开始再次启动B,并获得捆绑包的NPE…只需完成C,无需再次启动B