`
yzyspy
  • 浏览: 81026 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ActivityGroup 与TabActivity

 
阅读更多

首先定义一个主布局文件

hello_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/cust_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn"
        android:textColor="@android:color/white"
        android:textSize="28sp" />

    <!-- 中间动态加载View -->

    <ScrollView
        android:id="@+id/containerBody"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:measureAllChildren="true" >
    </ScrollView>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@android:color/black"
        android:orientation="horizontal" >

        <!-- 功能模块按钮1 -->

        <Button
            android:text="@string/btn"
            android:id="@+id/btnModule1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="7dp"
            android:layout_marginTop="3dp" />
        <!-- 功能模块按钮2 -->

        <Button
             android:text="@string/btn"
            android:id="@+id/btnModule2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="7dp"
            android:layout_marginTop="3dp" />
        <!-- 功能模块按钮3 -->

        <Button
             android:text="@string/btn"
            android:id="@+id/btnModule3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="3dp"
            android:layout_marginLeft="7dp"
            android:layout_marginTop="3dp" />
    </LinearLayout>

</LinearLayout>
   
HelloActivity.java
/*
 * Copyright (C) 2007 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.example.android.helloactivity;
import android.view.View;
import android.content.ComponentName;
import android.content.Intent;
import android.widget.Button;
import android.widget.ScrollView;
//import android.media.MediaScanner; @hide
import android.media.MediaPlayer;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.SystemClock;
import android.graphics.Paint;
import android.os.Handler;
import android.widget.Toast;
import android.util.Log;
public class HelloActivity extends ActivityGroup {

    //am start -n com.cmcc.mbbms/com.cmcc.mbbms.MainActivity
    
    private ScrollView container = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 隐藏标题栏
      //  requestWindowFeature(Window.FEATURE_NO_TITLE);
        // 设置视图
        setContentView(R.layout.hello_activity);

        container = (ScrollView) findViewById(R.id.containerBody);

        // 模块1
        Button btnModule1 = (Button) findViewById(R.id.btnModule1);
        btnModule1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                container.removeAllViews();
                Intent intent =  new Intent();
                ComponentName comp = new ComponentName(
                        "com.cmcc.mbbms",
                        "com.cmcc.mbbms.MainActivity");
                intent.setComponent(comp);
            
                container.addView(getLocalActivityManager().startActivity(
                        "Module1",
                        intent)
                        .getDecorView());
            }
        });

        // 模块2
        Button btnModule2 = (Button) findViewById(R.id.btnModule2);
        btnModule2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                container.removeAllViews();
                Intent intent =  new Intent();
                ComponentName comp = new ComponentName(
                        "com.android.calendar",
                        "com.android.calendar.MonthActivity");
                intent.setComponent(comp);
            
                container.addView(getLocalActivityManager().startActivity(
                        "Module2",
                        intent)
                        .getDecorView());
            }
        });


        // 模块3
        Button btnModule3 = (Button) findViewById(R.id.btnModule3);
        btnModule3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                container.removeAllViews();
                Intent intent =  new Intent();
                ComponentName comp = new ComponentName(
                        "com.android.soundrecorder",
                        "com.android.soundrecorder.SoundRecorder");
                intent.setComponent(comp);
            
                container.addView(getLocalActivityManager().startActivity(
                        "Module3",
                        intent)
                        .getDecorView());
            }
        });

    }
}
  

ActivityGroup 为什么不能启动一个其他进程的Activity

解决方法:
1、在activityThread.java的代码里添加对安全忽略即可。
 r.packageInfo = getPackageInfo(aInfo.applicationInfo,
  Context.CONTEXT_INCLUDE_CODE + Context.CONTEXT_IGNORE_SECURITY);

2、
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.test"
  android:versionCode="1"
  android:sharedUserId="com.android.activitygrouptest"
  android:versionName="1.0">

设定sharedUserId一致就可以了,这样两个apk会加载到同一个process中运行,同时要把你要启动的activity launchemode 设定为singletop。

 

 

只能启动同一个进程的Actvity  Intent intent =  new Intent(HelloActivity.this,HelloActivity1.class);

public class HelloActivity2 extends ActivityGroup {

     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       //动态添加按钮
        LinearLayout  tp = new LinearLayout(this);
        LayoutParams ltp = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
        Button btn = new Button(this);
        btn.setWidth(100);
        btn.setText("HelloActivity2");
        tp.addView(btn,ltp);
        this.setContentView(tp);
    }
}
 

 

 

 

分享到:
评论

相关推荐

    ActivityGroup 代替TabActivity的用法

    TabActivity已经被废除,而使用ActivityGroup 代替TabActivity,能够更加自由灵活,少很多限制和依赖!

    fragment tabhost 精美底部导航栏源代码

    实现了一个精美的底部导航栏,使用fragment替代了过时的activitygroup和tabactivity。里面有详细的注释,解释了每一步为什么要这么操作。相信每一个coder都能看明白。

    tabhost和ActivityGroup的组合使用

    android中tabhost和ActivityGroup的组合使用,特别是对多个Activity之间的跳转,压栈出战的管理,很有帮助。

    Android TabHost内嵌ActivityGroup界面管理源码.zip

    其中也包括了TabActivity去实现的,TabActivity 里面每个选项卡里面会有个默认的界面,但是当你的应用这个模块里面不止是一个界面,并且第二个界面里面,还需要你去显示下面的选项卡,很多人都会用到ActivityGroup,...

    Android源码——TabHost内嵌ActivityGroup界面管理源码_new_17.7z

    Android源码——TabHost内嵌ActivityGroup界面管理源码_new_17.7z

    ActivityGroup框架

    Android基于ActivityGroup项目框架,此框架和tabActivity不一样,每个tab下都可以建立多个Activity。

    Android之ActivityGroup + GridView 实现Tab分页标签

    读者也许会马上想到使用TabHost 与 TabActivity的组合,其实最常用的不是它们,而是由GridView与ActivityGroup的组合。每当用户在GridView选中一项,ActivityGroup就把该项对应的Activity的Window作为View添加到...

    Android Fragment应用实战Demo,向ActivityGroup说再见 源码程序

    此为示例代码,详细讲解请参考: http://blog.csdn.net/guolin_blog/article/details/13171191 如对资源内容有疑问,请到博客里留言。

    ActivityGroup|顶部底部均有Tab标签之二

    ActivityGroup|顶部底部均有Tab标签之二 http://blog.csdn.net/geofferysun/article/details/41852605

    Android入门之ActivityGroup+GridView实现Tab分页标签的方法

    读者也许会马上想到使用TabHost 与 TabActivity的组合,其实最常用的不是它们,而是由GridView与ActivityGroup的组合。每当用户在GridView选中一项,ActivityGroup就把该项对应的Activity的Window作为View添加到...

    Android TabHost内嵌ActivityGroup界面管理

    其中也包括了TabActivity去实现的,TabActivity 里面每个选项卡里面会有个默认的界面,但是当你的应用这个模块里面不止是一个界面,并且第二个界面里面,还需要你去显示下面的选项卡,很多人都会用到ActivityGroup,...

    Android自定义TabActivity(实现仿新浪微博底部菜单更新UI)

    自定义菜单布局+ActivityGroup+多个Activity的方式实现仿新浪微博底部菜单更新UI) 详解:http://blog.csdn.net/pocoyoshamoo/article/details/24708715

    android UI源码.zip

    实现TabHost有三种方式:继承自TabActivity,ActivityGroup和自定义的Activity 实现 备注:我在继承TabActivity的时候,将TabWidget的android:layout_height设置为"fill_parent"时,tab中不显示任何东西。如图: ...

    基于GridView和ActivityGroup实现的TAB分页(附源码)

    分页大家都会用Android的TabHost和TabActivity的组合,今天我这里实现的是GridView和ActivityGroup实现的分页,这里需要将Activity转换成Window,然后再换成成View添加到容器中,效果如下 1.布局文件底部放一个...

    Android Fragment案例

    Fragment应用实战案例,联系使用Android中的fragment,替换TabActivity,ActivityGroup;更多详细内容请访问 http://blog.csdn.net/qq_20889581/article/details/50407863 阅读浏览

    Android底部标签页的代码例子

    Android底部标签页的代码例子,提供了三种实现方式,分别是:使用TabActivity实现、使用ActivityGroup实现、使用FragmentActivity实现。

    Fragment框架demo

    Fragment,通过Api可以发现原来使用用于构建普通应用程序的框架的一些类,比如TabActivity,ActivityGroup都已经不推荐使用了,转而替换成Fragment。继承FragmentActivity

    学习android的40个实例源码

    CamMoniter,Snake,ActivityGroup,Android Emulater,Android的ADB工具的使用,Animation_Activity,Animation_Demo,Camera_Demo1,CameraTest. Download_Demo,DemoGeneralForm,SpashScreen,ViewFlipperDemo, ...

    android项目框架搭建

    包括 android页面左右滑动(采用android-support-v4.jar 中的 fragment来替换 4.0已经废弃的 TabActivity、ActivityGroup等)、检测GPS定位是否打开、network是否可用、控件加载异步图片等等 希望对您初期项目搭建...

    androidmai

    在一个主界面中做Activity切换一般都会用TabActivity,使用方便,Activity互相之间相对独立,但是可定制性不强,而且修改起来很麻烦。当然也可以把layout分开,把逻辑代码全写在主界面的逻辑代码中,但是很明显可...

Global site tag (gtag.js) - Google Analytics