码迷,mamicode.com
首页 > 移动开发 > 详细

android 23 启动带2个Categories值的预定义acticity和桌面activity

时间:2015-10-17 07:00:06      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

mainActivity.java

package com.sxt.day04_07_twoaction;

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

public class MainActivity extends Activity implements OnClickListener{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        setListener();
    }

    private void setListener() {
        findViewById(R.id.btn1).setOnClickListener(this);
        findViewById(R.id.btn2).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent=new Intent();
        intent.setAction("com.sxt.day04_07_twoaction.SecondActivity");
        switch (v.getId()) {
        case R.id.btn1:
            intent.addCategory("com.sxt.day04_07_twoaction.category");
            break;
        case R.id.btn2:
            intent.addCategory("android.intent.category.DEFAULT");
            break;
        }
        startActivity(intent);
    }
}

系统描述文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.sxt.day04_07_twoaction"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.sxt.day04_07_twoaction.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="com.sxt.day04_07_twoaction.SecondActivity"
            android:label="@string/title_activity_second" >
            <intent-filter>
                <action android:name="com.sxt.day04_07_twoaction.SecondActivity"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="com.sxt.day04_07_twoaction.category"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

 

android 23 启动带2个Categories值的预定义acticity和桌面activity

标签:

原文地址:http://www.cnblogs.com/yaowen/p/4886816.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!