Android之Activity 2
来源:互联网 发布:城市人口密度数据 编辑:程序博客网 时间:2024/04/30 05:13
android提倡的标准方法是使用intent来实现两个screen之间的跳转,说到screen和activity的区别,我也不是很清楚,目前我的理解就是screen = activity。因为要使用两个activity,所以首先要在AndroidManifest.xml声明有两个activity,如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Android.HelloThree">
<application android:icon="@drawable/icon">
<activity android:name=".HelloThree" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HelloThreeB" android:label="@string/app_name">
</activity>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Android.HelloThree">
<application android:icon="@drawable/icon">
<activity android:name=".HelloThree" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".HelloThreeB" android:label="@string/app_name">
</activity>
</application>
</manifest>
看到网上的同志们的xml是这样写的
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Android.HelloThree">
<application android:icon="@drawable/icon">
<activity class=".HelloThree" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity class=".HelloThreeB" android:label="@string/app_name">
</activity>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.Android.HelloThree">
<application android:icon="@drawable/icon">
<activity class=".HelloThree" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity class=".HelloThreeB" android:label="@string/app_name">
</activity>
</application>
</manifest>
与我的不相同是activity以class命名,我尝试了一下,但是总是报错,也不知道是什么原因......
之后的类定义如下:
public void onCreate(Bundle icicle)...{
super.onCreate(icicle);
setTheme(android.R.style.Theme_Dark);
setContentView(R.layout.main);
setViewOneCommand();
}
public void setViewOneCommand()
...{
Button btn = (Button)findViewById(R.id.go);
btn.setOnClickListener(new View.OnClickListener()
...{
public void onClick(View v)
...{
Intent intent = new Intent();
intent.setClass(HelloThree.this, HelloThreeB.class);
startActivity(intent);
finish();
}
});
Button btnExit=(Button)findViewById(R.id.exit);
btnExit.setOnClickListener(new View.OnClickListener()...{
public void onClick(View v)...{
HelloThree.this.finish();
}
});
}
super.onCreate(icicle);
setTheme(android.R.style.Theme_Dark);
setContentView(R.layout.main);
setViewOneCommand();
}
public void setViewOneCommand()
...{
Button btn = (Button)findViewById(R.id.go);
btn.setOnClickListener(new View.OnClickListener()
...{
public void onClick(View v)
...{
Intent intent = new Intent();
intent.setClass(HelloThree.this, HelloThreeB.class);
startActivity(intent);
finish();
}
});
Button btnExit=(Button)findViewById(R.id.exit);
btnExit.setOnClickListener(new View.OnClickListener()...{
public void onClick(View v)...{
HelloThree.this.finish();
}
});
}
可以看到在hellothree这个activity中有两个按钮,按go,它就会启动第二个activity,按exit,它就会退出。相应的,我们必须定义hellothreeb这个activity。如下:
public void onCreate(Bundle icicle)...{
super.onCreate(icicle);
setTheme(android.R.style.Theme_Dark);
setContentView(R.layout.second);
setviewTwocommand();
};
public void setviewTwocommand()...{
Button btn2 = (Button)findViewById(R.id.go2);
btn2.setOnClickListener(new View.OnClickListener()
...{
public void onClick(View v)
...{
Intent intent = new Intent();
intent.setClass(HelloThreeB.this, HelloThree.class);
startActivity(intent);
finish();
}
});
};
super.onCreate(icicle);
setTheme(android.R.style.Theme_Dark);
setContentView(R.layout.second);
setviewTwocommand();
};
public void setviewTwocommand()...{
Button btn2 = (Button)findViewById(R.id.go2);
btn2.setOnClickListener(new View.OnClickListener()
...{
public void onClick(View v)
...{
Intent intent = new Intent();
intent.setClass(HelloThreeB.this, HelloThree.class);
startActivity(intent);
finish();
}
});
};
我在这个activity中定义了一个按钮来实现回到前一个screen的功能,由此实现两个screen之间的跳转。但是此处仍然不能实现数据的传递。
- Android之Activity 2
- Android 四大组件之 Activity(2)--传值
- Android组件介绍之Activity(2)
- Android应用组件之Activity介绍2
- Android之activity
- Android 之 Activity 生命周期
- android之activity生命周期
- Android 之 Activity 生命周期
- android 之 Task Activity
- Android之Activity学习
- android组件之Activity
- 精通android之Activity
- Android之Activity
- android 之 Activity lifecycle
- 05.Android之Activity
- Android之Activity
- Android入门之Activity
- Android之Activity组件
- AIX hacmp oracle9i ORA-32700: error occurred in DIAG Group service
- "字符流"与"字节流"的简单理解
- 在RedHat Enterprise Linux5上安装MySQL
- 数据结构---顺序表
- 数据结构---链表
- Android之Activity 2
- 如何在windows程序中读取bios内容
- 数据结构---栈
- margin属性的四个方向的顺序
- 关于主对话框数据于子对话框数据的交换
- kbox1.03版
- 数据结构---队列
- 搜索spider对二叉查找树查找实验(中文翻译)
- 数据结构---字符串