Activity跳转与返回

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}

两个
Activity
跳转,都是在第一个
Activity
调用
startActivity()
方法启动第二个
Activity
,然后在第二个
Activity
调用
Context.finish()
方法实现返回到第一个
Activity
。但是有的时候业务需求很复杂,从第二个
Activity
返回到第一个
Activity
时候,需要再次处理某些事情时就要使用
startActivityForResult()
方法启动第二个
Activity
了,并在第一个
Activity
中重写
onActivityResult()
方法。

@Override

public void onCreate(Bundle savedInstanceState)
{

         
super.onCreate(savedInstanceState);

         
setContentView(R.layout.main);

 

         
btnLogin = (Button)
findViewById(R.id.btnLogin);

         
userid = (EditText)
findViewById(R.id.userid);

         
pwd = (EditText)
findViewById(R.id.password);

 

         
btnLogin.setOnClickListener(new
View.OnClickListener() {

                  
@Override

                  
public void
onClick(View v) {

                            
if
(userid.getText().toString().equals("tony")

                                              
&&
pwd.getText().toString().equals("1")) {

                                     
Intent
it = new Intent(LoginActivity.this,

                                                        
SuccessActivity.class);

                                     
it.putExtra("userid",
userid.getText().toString());

                                     
startActivityForResult(it,
1);

                            
}
else {

                                     
Intent
it = new Intent(LoginActivity.this,

                                                        
FailureActivity.class);

                                     
startActivityForResult(it,
2);

                            
}

                  
}

         
});

}

 

@Override

protected void
onActivityResult(int requestCode, int resultCode, Intent data) {

         
switch (requestCode)
{

         
case 1:

                  
//
登录成功之后返回的。

                  
Log.v(TAG,
"from success activity return. resultCode=" + resultCode);

                  
break;

         
case 2:

                  
//
登录失败之后返回的。

                  
Log.v(TAG, "from failure activity return.
resultCode=" + resultCode);

         
}

         
super.onActivityResult(requestCode,
resultCode, data);

 

}

 

}

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}

成功屏幕
SuccessActivity

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}

public class SuccessActivity extends Activity {

 

Button btnBack;

TextView label;

 

@Override

protected void onCreate(Bundle
savedInstanceState) {

         
super.onCreate(savedInstanceState);

         
setContentView(R.layout.success);

 

         
label = (TextView)
findViewById(R.id.label);

         
Bundle bundle =
this.getIntent().getExtras();

         
String userid =
bundle.getString("userid");

         
label.setText(userid);

         
btnBack = (Button)
findViewById(R.id.btnBack);

         
btnBack.setOnClickListener(new
View.OnClickListener() {

 

                  
@Override

                  
public void
onClick(View v) {

                            
setResult(4,
(new Intent()).putExtra("name", label.getText()

                                              
.toString()));

                            
SuccessActivity.this.finish();

                  
}

         
});

 

}

 

}

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}

失败屏幕
FailureActivity

Normal
0

7.8 磅
0
2

false
false
false

EN-US
ZH-CN
X-NONE

MicrosoftInternetExplorer4

/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}

public class FailureActivity extends Activity {

Button btnBack ;

TextView label;

@Override

protected void onCreate(Bundle
savedInstanceState) {

         
super.onCreate(savedInstanceState);

         
setContentView(R.layout.failure);

         
label 
= (TextView)findViewById(R.id.label);

         
btnBack =
(Button)findViewById(R.id.btnBack);

         
btnBack.setOnClickListener(new
View.OnClickListener() {

 

                  
@Override

                  
public void
onClick(View v) {

                            
setResult(5);

                            
FailureActivity.this.finish();

                  
}

         
});

 

}

 

}

时间: 2024-12-01 02:01:39

Activity跳转与返回的相关文章

android 监听返回键怎么从activity 跳转到tabhost主页且选项卡不消失?

问题描述 android 监听返回键怎么从activity 跳转到tabhost主页且选项卡不消失? 我用activity 和tabhost配套使用,当监听返回键时跳转到tabhost主页,发现选项卡消失,不只是为什么?求各位大神解答?谢谢! 解决方案 那要看你点击返回键的函数里面是怎么跳转的

android的activity跳转到另一个activity_Android

开发环境:android4.1.1 实验功能:在第一个Hello World!为标签的activity中显示good,该界面中有一个名为Next的按钮.点击Next按钮进入到第二个activity中去,第二个界面中只有1个Close按钮.当然,据网上有人将要比较安全的实现关闭程序的功能也不是挺简单的,因为android有专门的退出键返回键等.所以该Close按钮暂时没去实现它.我的第1个activity为HelloworldActivity,第2个activity为NextActivity. 实

activity-Android Activity跳转问题

问题描述 Android Activity跳转问题 有3个Activity,A,B,C,点击A,跳转到B,点击B的1按钮返回A,点击B的2按钮调转到C,在C中点击1按钮返回B,点击2按钮直接跳转到A,并结束掉B 该怎么实现 解决方案 ??? 最近在用Android写一个商品导购程序的时候遇到了一个问题:这个程序中有四个Activity A.B.C.D:其中A用来填写购买商品时的一些客户信息,填写完毕后点击按钮触发事件跳转到B:B用来显示商品的所有分类,选中其中一个分类之后跳转到C:C界面用来显示

android activity跳转

问题描述 android activity跳转 有A.B.C.D 四个Activity ,每个Activity 都有相同的一个导航菜单,原理跟网站导航一样能任意跳转至其他的Activity, 我用的是StarActivity(intent)方法.这样的话问题出现了,每次的都是重新打开Activity.我想要的效果是,如果要跳转的那个Activity是已经打开过了的就直接像显示它,而不是重新去打开,请问有什么好的解决方法吗?谢谢!!!!!!!! 解决方案 看以看看这个链接google androi

activity跳转效果-Activity页面跳转怎样实现从下往上覆盖的效果

问题描述 Activity页面跳转怎样实现从下往上覆盖的效果 在网上搜索基本实现了activity跳转从下往上的功能,但是效果不是覆盖的感觉而是底下的activity变没了之后,怎么让底下的activity感觉是被另一个activity是从下被覆盖掉的. 解决方案 activity.overridePendingTransition(进场动画, 出场动画); 解决方案二: 在启动跳转的地方添加overridePendingTransition(int resId,int resId);这两个参数

页面跳转-请教一个Activity跳转到另外一个Activity失败的问题

问题描述 请教一个Activity跳转到另外一个Activity失败的问题 package com.example.t; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; impo

Android activity跳转与线程启动问题

问题描述 Android activity跳转与线程启动问题 package com.example.gteetcard; import android.annotation.SuppressLint;import android.app.Activity;import android.content.Intent;import android.media.MediaPlayer;import android.os.Bundle;import android.os.Handler;import

界面-Android 从activity跳转进入另一个activity内viewpager的指定页面

问题描述 Android 从activity跳转进入另一个activity内viewpager的指定页面 求助: 现在的需求是, 要从activityA跳转进入另一个activityB内viewpager的第4个界面 (activityB一共有4个fragment组成viewpager) 注:看清需求,不是activityA跳转到activityB,而是要跳转到activityB内部viewpager里面的一个指定页面 解决方案 直接在activityB中设置viewPager.setCurre

android-Android. 如何实现viewpager里面的一个条目向Activity跳转

问题描述 Android. 如何实现viewpager里面的一个条目向Activity跳转 Android. 如何实现viewpager里面的一个条目作为点击时间,向Activity跳转,不知道如何做,求大神们帮忙 解决方案 Android实现Activity的跳转android 实现各activity之间的跳转android用Intent实现Activity跳转 解决方案二: 比如fragment里面有个button,点击button事件监听,Intent intent = new Inten