Activity显示/隐式调用

Activity显示/隐式调用,主要通过intent-filter实现

其中category的各项属性值及含义

常量

含义

CATEGORY_BROWSABLE

目标activity可以使用浏览器来显示-例如图片或电子邮件消息.

CATEGORY_GADGET

该activity可以被包含在另外一个装载小工具的activity中.

CATEGORY_HOME

该activity显示主屏幕,也就是用户按下Home键看到的界面.

CATEGORY_LAUNCHER

该activity可以作为一个任务的第一个activity,并且列在应用程序启动器中.

CATEGORY_PREFERENCE

该activity是一个选项面板.

实例代码

package com.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * @author WonderCoder
 * @time 2012-3-30
 * Activity间的切换
 *
 */
public class MainActivity extends Activity implements OnClickListener {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Button bt1 = (Button)findViewById(R.id.button1);
        Button bt2 = (Button)findViewById(R.id.button2);
        Button bt3 = (Button)findViewById(R.id.button3);
        
        bt1.setOnClickListener(this);
        bt2.setOnClickListener(this);
        bt3.setOnClickListener(this);
    }

	public void onClick(View view) {
		Intent intent = null;
		switch(view.getId()){
		case R.id.button1:
			intent = new Intent(this,MyActivity1.class);
			break;
		case R.id.button2:
			intent = new Intent("myaction1");
			break;
			
		case R.id.button3:
			intent = new Intent("myaction2");
			intent.addCategory("mycategory");
			break;
		}
		startActivity(intent);
	}
    
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <Button android:text="显示调用Activity" 
    	android:id="@+id/button1" 
    	android:layout_width="fill_parent" 
    	android:layout_height="wrap_content">
    	</Button>
    	
    <Button android:text="隐式调用Activity" 
    	android:id="@+id/button2" 
    	android:layout_width="fill_parent" 
    	android:layout_height="wrap_content">
    	</Button>
    	
    <Button android:text="隐式调用两个符合过滤条件的Activity" 
    	android:id="@+id/button3" 
    	android:layout_width="fill_parent"
    	android:layout_height="wrap_content">
    	</Button>
</LinearLayout>
运行结果:





  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值