最近在工作中,研究了工作流,这里借助网络上的一些资料,和大家分享下工作流的入门!
<span style="font-size:18px;"><span style="font-size:18px;">package com.android.ttx.actiitylifedemo; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; public class ActivityLifeDemo extends Activity { private final static String TAG="ActivityLifeDemo"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Log.i(TAG, "onCreate"); } @Override protected void onStart() { Log.i(TAG, "onStart"); super.onStart(); } @Override protected void onRestart() { Log.i(TAG, "onRestart"); super.onRestart(); } @Override protected void onResume() { Log.i(TAG, "onResume"); super.onResume(); } @Override protected void onPause() { Log.i(TAG, "onPause"); super.onPause(); } @Override protected void onStop() { Log.i(TAG, "onStop"); super.onStop(); } @Override protected void onDestroy() { Log.i(TAG, "onDestroy"); super.onDestroy(); } } </span> </span>
<span style="font-size:18px;">1、 运行 看到如下打印日志: 08-31 08:46:53.916: INFO/ActivityLifeDemo(312): onCreate 08-31 08:46:53.916: INFO/ActivityLifeDemo(312): onStart 08-31 08:46:53.916: INFO/ActivityLifeDemo(312): onResume 2、按下返回按键: 08-31 09:29:57.396: INFO/ActivityLifeDemo(354): onPause 08-31 09:29:58.216: INFO/ActivityLifeDemo(354): onStop 08-31 09:29:58.216: INFO/ActivityLifeDemo(354): onDestroy 3、长按Home键,弹出最近打开过的应用程序,点击ActivityLifeDemo 08-31 08:51:46.916: INFO/ActivityLifeDemo(312): onCreate 08-31 08:51:46.916: INFO/ActivityLifeDemo(312): onStart 08-31 08:51:46.936: INFO/ActivityLifeDemo(312): onResume 4、按Home键 08-31 08:53:32.676: INFO/ActivityLifeDemo(312): onPause 08-31 08:53:33.796: INFO/ActivityLifeDemo(312): onStop 5、在AllList中点击打开 08-31 08:54:14.286: INFO/ActivityLifeDemo(312): onRestart 08-31 08:54:14.286: INFO/ActivityLifeDemo(312): onStart 08-31 08:54:14.296: INFO/ActivityLifeDemo(312): onResume </span>
<span style="font-size:18px;"><span style="font-size:18px;">Intent intent = new Intent(this, ActivityDemo.class); startActivity(intent); // ActivityDemo是需要启动的Activity类 </span> </span>
<span style="font-size:18px;"><span style="font-size:18px;">Intent intent = new Intent(this,ActivityDemo.class); Bundle bundle = new Bundle(); bundle.putBoolean("bool_key", true); intent.putExtras(bundle); startActivity(intent); </span> </span>
<span style="font-size:18px;"><span style="font-size:18px;">Intent intent = new Intent(ActivityLifeDemo.this,RevalueActivity.class); startActivityForResult(intent, 0x1001); </span> ActivityLifeDemo是当前的Activity,启动RevalueActivity,我们在ActivityLifeDemo中需要获取RevalueActivity传回来的值。那么在RevalueActivity中就必须这样写: <span style="font-size:18px;">Intent intent = new Intent(); intent.putExtra("revalue_key","haha-revalueActivity"); setResult(0x1001, intent);</span> 那么“revalue_key”值在哪里获取呢?必须重写onActivityResult方法,通过判断requestCode,来确定 <span style="font-size:18px;">if(requestCode==0x1001){ String str = data.getStringExtra("revalue_key"); Log.i(TAG, "返回的值为:"+str); } </span> </span>
大家看到这里对工作流有了个简单的认识,咱们也有了理解,其实任何一种技术,都是对前辈问题的解决,而工作流就是对以前流程问题的总结,说白了,这里的所有的代码都是对以前重复问题的总结!
学习任何一种技术,只要从战略上先蔑视他,然后从战术上重视他,他就不是问题!