即使在编写的代码完全相同之后,也无法在两个活动之间进行链接

时间:2013-05-06 18:51:21

标签: java android

这是两个相互关联的活动,但这些活动不起作用 我在xml文件中提供了方法名称onClick =“menu”这两个按钮和方法

public class Welcome extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcome);

/**Intent i = new Intent(this,Menup.class);
    finish();
    startActivity(i);*/
}

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

public void menu(View v)
{
    finish();
    Intent i = new Intent(this,Menup.class);
    startActivity(i);

}
}

它将被移动到下一个活动名称和代码

public class Menup extends Activity {

Button route,map,ticket;
TextView bal;
String time,src,des,clas,journey,noa,noc,amount;
int itime,old=50,amt,camt;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menup);

    bal=(TextView)findViewById(R.id.textView1);

    //getting the values
    Intent i=getIntent();
    time=i.getExtras().getString("time");
    itime=Integer.valueOf(time);
    src=i.getExtras().getString("src");
    des=i.getExtras().getString("des");
    clas=i.getExtras().getString("class");
    journey=i.getExtras().getString("journey");
    noa=i.getExtras().getString("noa");
    noc=i.getExtras().getString("noc");
    amount=i.getExtras().getString("amount");
    camt=Integer.valueOf(amount);

    route=(Button)findViewById(R.id.imageButton1);
    map=(Button)findViewById(R.id.imageButton2);
    ticket=(Button)findViewById(R.id.imageButton3);

    route.getBackground().setAlpha(0);
    map.getBackground().setAlpha(0);
    ticket.getBackground().setAlpha(0);

    amt=old-camt;
    bal.setText("Current Balance   "+amt);
}

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

public void toroute(View v)
{
    Intent r = new Intent(Menup.this,Route.class);
    startActivity(r);
}

public void tomap(View v)
{
    Intent m = new Intent(Menup.this,Map.class);
    startActivity(m);
}

public void toticket(View v)
{

    Intent d=new Intent(Menup.this,Tick.class);
    d.putExtra("noa",noa);
    d.putExtra("noc",noc);
    d.putExtra("src",src);
    d.putExtra("des",des);
    d.putExtra("class", "Class I");
    d.putExtra("journey", "Single");
    d.putExtra("amount", amount);
    d.putExtra("time", itime);
    startActivity(d);
}

@Override
public void onBackPressed() 
{

    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle("Exit");
    builder.setMessage("Are you sure , you want to exit Ticketwala?");

    builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // Do nothing but close the dialog
            finish();
            System.exit(0);
            dialog.dismiss();
        }

    });

    builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Do nothing
            dialog.dismiss();
        }
    }).show();
}
}

1 个答案:

答案 0 :(得分:0)

在开始下一个活动之前,您不必“完成()”您的活动欢迎。但如果必须,请将其放在startActivity();

之后