安卓学习笔记(一)、使用application传递数据
来源:互联网 发布:java jdbc 连接池 编辑:程序博客网 时间:2024/04/29 08:39
public class MainActivity extends Activity {public Button button;private MyApp myApp;@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button) this.findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubmyApp = (MyApp) getApplication();myApp.setName("jack");Intent intent = new Intent(MainActivity.this,OtherActivity.class);startActivity(intent);}}); }
public class MyApp extends Application {public String name;public String getName() {return name;}public void setName(String name) {this.name = name;}@Overridepublic void onCreate() {// TODO Auto-generated method stubsuper.onCreate();setName("张三");}}
public class OtherActivity extends Activity {private MyApp myApp;private TextView textView;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.other);textView = (TextView) this.findViewById(R.id.msg);myApp = (MyApp) getApplication();textView.setText("--appname-->>"+myApp.getName());}}
<application android:name=".MyApp" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" 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=".OtherActivity"> </activity> </application>
0 0
- 安卓学习笔记(一)、使用application传递数据
- 安卓学习笔记(二) 使用Intent传递数据
- 安卓学习笔记(二)、使用剪切板传递数据
- 安卓学习笔记(三)、使用Intent传递数据
- 安卓学习笔记(四)、使用静态变量传递数据
- 安卓学习笔记(五)、使用Intent返回数据
- 安卓笔记Activity间传递数据
- 安卓学习笔记<一>:数据存储之SharedPreferences
- 安卓学习笔记(一)
- 安卓学习笔记整理(一)
- 安卓开发学习笔记(一)
- 安卓学习笔记(一)
- 安卓学习笔记一
- 安卓学习笔记一
- 安卓传递数据
- 【Android】安卓学习笔记之使用SharedPreferences 读写数据
- oschina客户端安卓研究(一)xml方式传递数据
- Application对象使用与数据传递
- iOS应用安全Part39:获取内存中的敏感信息
- ural 1507 Difficult Decision
- setjmp用法
- 产品经理的第一次面试总结
- android处理处理触屏事件的流程
- 安卓学习笔记(一)、使用application传递数据
- C++ 类模板成员
- 批量从NCBI后台下载指定数据的Perl脚本
- Codeforces Round #297 (Div. 2) D Arthur and Walls
- 关于读很好的解释
- 第三周周记
- 12、@synthesize of ‘weak’ property is only allowed in ARC or GC mode
- 2015年CSDN博客排名第一名,何方神圣?
- PHP基础-echo,print,print_r,var_export,var_dump