激活状态(运行状态)---->暂停状态---->停止状态。
活动生命周期的方法:onCreate(),onRestart(),onStart(),onResume(),onPause(),onStop(),onDestory().
打电话的应用程序源码如下:
Activity中的代码如下:
package com.cgz.callphone;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {
EditText editText;
Button callbtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//选择界面
setContentView(R.layout.activity_main);
//查找组件---输入框
editText=(EditText)this.findViewById(R.id.editText1);
//得到按钮
callbtn=(Button)this.findViewById(R.id.button1);
//设置监听
callbtn.setOnClickListener(new MyListener());
}
class MyListener implements View.OnClickListener{
@Override
public void onClick(View v) {
//获取用户输入的电话号码
String callNum = editText.getText().toString();
//创建意图对象
Intent intent=new Intent();
//设置意图动作
intent.setAction("android.intent.action.CALL");
//设置电话号码
intent.setData(Uri.parse("tel:"+callNum));
//启动意图
startActivity(intent);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}


}
注册页面中的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cgz.callphone"
android:versionCode="1"
android:versionName="1.0" >
<!-- 注册权限 -->
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.cgz.callphone.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>
</application>

</manifest>
Layout中的布局页面代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="请输入你的手机号码:" />

<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:ems="10"
android:inputType="phone" >

<requestFocus />
</EditText>

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText1"
android:layout_below="@+id/editText1"
android:layout_marginTop="14dp"
android:text="拨号" />

</RelativeLayout>

更多相关文章

  1. 没有一行代码,「2020 新冠肺炎记忆」这个项目却登上了 GitHub 中
  2. Android封装类似微信的顶部TitleBar弹出的PopupWindow代码
  3. Android多媒体学习十五:使用在内置的Camera录制视频
  4. [android Studio] unhandled exception: android.os.RemoteExcep
  5. WebRTC Android(安卓)源码编译
  6. Android的系统服务一览 .
  7. Android(安卓)获取window状态栏和标题栏的高度
  8. rk3326 android 8.1 上传sftp时候jsch类报错
  9. Android(安卓)集成 Zxing 条码扫描器

随机推荐

  1. Android获取Mac地址
  2. android再点一次返回退出
  3. Android(安卓)8.0和8.1通知栏
  4. Android(安卓)wifi休眠策略
  5. android Intent类
  6. android音乐播放器源码java类
  7. Android中文文档笔记①
  8. android 使用广播监听网络状态
  9. DataBinding(双向绑定)
  10. Ubuntu环境变量