zoukankan      html  css  js  c++  java
  • android之隐式intent调用

    直接上代码

    MainActivity.java

     1 package com.example.test1;
     2 
     3 import android.app.Activity;
     4 import android.content.Intent;
     5 import android.net.Uri;
     6 import android.os.Bundle;
     7 import android.view.View;
     8 import android.view.View.OnClickListener;
     9 import android.widget.Button;
    10 
    11 public class MainActivity extends Activity {
    12 
    13     @Override
    14     protected void onCreate(Bundle savedInstanceState) {
    15         super.onCreate(savedInstanceState);
    16         setContentView(R.layout.activity_main);
    17     
    18         Button btnButton = (Button) findViewById(R.id.button1);
    19         
    20         btnButton.setOnClickListener(new OnClickListener() {
    21             
    22             @Override
    23             public void onClick(View v) {
    24                 // TODO Auto-generated method stub
    25                 Intent intent = new Intent();
    26                 intent.setAction("aa.bb.cc.dd.ee.ff");
    27                 
    28                 startActivity(intent);
    29             }
    30         });
    31     }
    32 }

    SecondActivity.java

     1 package com.example.test1;
     2 
     3 import android.app.Activity;
     4 import android.content.Intent;
     5 import android.os.Bundle;
     6 import android.widget.TextView;
     7 
     8 public class SecondActivity extends Activity {
     9 
    10     @Override
    11     protected void onCreate(Bundle savedInstanceState) {
    12         
    13         super.onCreate(savedInstanceState);
    14         
    15         setContentView(R.layout.second_main);
    16 
    17         Intent intent = getIntent();
    18         
    19         TextView textView = (TextView) findViewById(R.id.textView1);
    20         textView.setText(intent.getAction());
    21     }
    22 }

    activity_main.xml

     1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="http://schemas.android.com/tools"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent"
     5     android:paddingBottom="@dimen/activity_vertical_margin"
     6     android:paddingLeft="@dimen/activity_horizontal_margin"
     7     android:paddingRight="@dimen/activity_horizontal_margin"
     8     android:paddingTop="@dimen/activity_vertical_margin"
     9     tools:context=".MainActivity" >
    10 
    11     <Button
    12         android:id="@+id/button1"
    13         android:layout_width="wrap_content"
    14         android:layout_height="wrap_content"
    15         android:layout_alignParentTop="true"
    16         android:layout_centerHorizontal="true"
    17         android:layout_marginTop="124dp"
    18         android:text="跳转" />
    19 
    20 </RelativeLayout>

    second_main.xml

     1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     xmlns:tools="http://schemas.android.com/tools"
     3     android:layout_width="match_parent"
     4     android:layout_height="match_parent"
     5     >
     6 
     7     <TextView
     8         android:id="@+id/textView1"
     9         android:layout_width="wrap_content"
    10         android:layout_height="wrap_content"
    11         android:layout_alignParentLeft="true"
    12         android:layout_alignParentTop="true"
    13         android:layout_marginLeft="93dp"
    14         android:layout_marginTop="176dp"
    15         android:text="Large Text"
    16         android:textAppearance="?android:attr/textAppearanceLarge" />
    17 
    18 </RelativeLayout>

    很重要的AndroidManifest.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     3     package="com.example.test1"
     4     android:versionCode="1"
     5     android:versionName="1.0" >
     6 
     7     <uses-sdk
     8         android:minSdkVersion="8"
     9         android:targetSdkVersion="17" />
    10 
    11     <application
    12         android:allowBackup="true"
    13         android:icon="@drawable/ic_launcher"
    14         android:label="@string/app_name"
    15         android:theme="@style/AppTheme" >
    16         <activity
    17             android:name="com.example.test1.MainActivity"
    18             android:label="@string/app_name" >
    19             <intent-filter>
    20                 <action android:name="android.intent.action.MAIN" />
    21 
    22                 <category android:name="android.intent.category.LAUNCHER" />
    23             </intent-filter>
    24         </activity>
    25         <activity android:name="com.example.test1.SecondActivity">
    26             <intent-filter>
    27                 <action android:name="aa.bb.cc.dd.ee.ff"/>
    28                 
    29                 <category android:name="android.intent.category.DEFAULT" />//隐式intent调用,这句必须加
    30             </intent-filter>
    31         </activity>
    32 
    33     </application>
    34 
    35 </manifest>
  • 相关阅读:
    关于sharepoint 2010 匿名环境下打开office文档避免登录框出现的解决办法
    sharepoint user profile
    烙饼排序1(最基本的排序) 下
    使用DevExpress.XtraReports.UI.XtraReport 设计报表的时候如何格式化字符串 下
    C#排序1(冒泡排序、直接排序、快速排序) 下
    C# winform中自定义用户控件 然后在页面中调用用户控件的事件 下
    单向非循环列表的简单操作 下
    C# 格式化字符串(网址) 下
    (转)C# Enum,Int,String的互相转换 枚举转换 下
    烙饼排序2(比较高效率的方法) 下
  • 原文地址:https://www.cnblogs.com/ziyouchutuwenwu/p/3097153.html
Copyright © 2011-2022 走看看