android activity什么时间不进生命周期
android activity什么时间不进生命周期情况是这样的,我用的tabHost 默认先加载 A-activity,然后从 A-activity 跳到 B-acticity ,
然后我在B-acticity中的OnResume中跳到A-activity,再进B-acticity他不进任何生命周期,
因为从B-acticity到A-activity不做onPause,但是为什么不做,百思不得其解 android --------------------编程问答-------------------- 使用TABHOST 在TAB页面的所有VIEW完全加载后,整个TAB是在交互状态。 --------------------编程问答-------------------- TAB加载完所有的actitity后,你再切换actitity 其实就是隐藏显示view一样,,,不象单独的activity的切换,这是有压栈 出栈的流程的 --------------------编程问答-------------------- 将VIEW加入TAB之后,VIEWROOT已经被改变。子VIEW的生命周期此时已经交于 TAB。 --------------------编程问答-------------------- 把你实现的代码帖出来,好吗? --------------------编程问答--------------------
public class MainActivity extends TabActivity {
private RadioGroup rgTab;
private TabHost mTabHost;
private Intent tab1Intent; // 首页
private Intent tab2Intent;// 活动
public final static String TAB1 = "tab1_";// 首页
public final static String TAB2 = "tab2_";// 活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rgTab = (RadioGroup) findViewById(R.id.rg_tab);
rgTab.setOnCheckedChangeListener(rgListener);
tabSetIntent();
}
/**
* 准备tab的内容Intent并添加
*/
private void tabSetIntent() {
tab1Intent = new Intent(this, Tab1Activity.class);
tab2Intent = new Intent(this, Tab2Activity.class);
// ADDTAB的顺序一定要和显示在页面上的顺序一致
this.mTabHost = getTabHost();
TabHost localTabHost = this.mTabHost;
localTabHost.addTab(buildTabSpec(TAB1, R.string.tab1, tab1Intent));
localTabHost.addTab(buildTabSpec(TAB2, R.string.tab2, tab2Intent));
}
private TabHost.TabSpec buildTabSpec(String tag, int lable,
final Intent content) {
return this.mTabHost
.newTabSpec(tag)
.setIndicator(
getString(lable),
getResources().getDrawable(
com.example.tabdemo.R.drawable.ic_launcher))
.setContent(content);
}
private RadioGroup.OnCheckedChangeListener rgListener = new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.tab1:
mTabHost.setCurrentTabByTag(TAB1);
break;
case R.id.tab2:
mTabHost.setCurrentTabByTag(TAB2);
break;
}
}
};
}
package com.example.tabdemo;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class Tab1Activity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setTextColor(Color.RED);
textView.setText("这是tab1");
setContentView(textView);
}
@Override
protected void onResume() {
super.onResume();
Log.e("", "tab1-onResume");
}
@Override
protected void onPause() {
super.onPause();
Log.e("", "tab1-onPause");
}
}
package com.example.tabdemo;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.TextView;
public class Tab2Activity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText(".........");
tv.setTextColor(Color.BLUE);
setContentView(tv);
}
@Override
protected void onResume() {
super.onResume();
Log.e("", "tab2-onResume");
TabHost th = (TabHost) getParent().findViewById(
android.R.id.tabhost);
RadioGroup rgTab = (RadioGroup) th
.findViewById(R.id.rg_tab);
((RadioButton) rgTab.getChildAt(0)).setChecked(true);
}
@Override
protected void onPause() {
super.onPause();
Log.e("", "tab2-onPause");
}
}
我做了个小实验,为什么两个布局绘到一个acticity上面去了
补充:移动开发 , Android