通过Intent实现返回桌面
来源:互联网 发布:js获取某个class 编辑:程序博客网 时间:2024/06/02 07:33
直接上代码:
main.xml:
<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" > <Button android:id="@+id/backToHost_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="返回桌面" /></RelativeLayout>
MainActivity.java:
package com.example.backtohome;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity {Button backToHostButton=null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);backToHostButton=(Button)findViewById(R.id.backToHost_button);backToHostButton.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Intent intent=new Intent();//设置Intent的动作,动作是作为初始Activity显示出来intent.setAction(Intent.ACTION_MAIN);//设置Intent的种类,让桌面作为初始的Activity显示出来intent.addCategory(Intent.CATEGORY_HOME);startActivity(intent);}});}@Overridepublic 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;}}
- 通过Intent实现返回桌面
- Intent对象练习1---返回系统桌面
- 通过 Intent传递数据,并返回结果
- 5 返回桌面 Intent的action 和 category 属性
- Intent实现页面的跳转和返回
- Android中实现返回桌面的代码
- 通过Intent启动Activity、获取Activity返回值
- Android实现点击返回键返回桌面而不是退出程序
- android Intent 实现跳转 通过注册表
- 返回桌面
- 返回桌面
- Android的intent:基础以及显示/隐式使用Intent,SD挂载识别&& 通过intent返回结果
- 【Android】使用Intent实现数据传递之返回结果
- 通过CountDownLatch实现websocket同步返回
- 用代码通过Intent实现apk文件的安装
- android:cha1.2 通过Intent实现Activity之间的通信
- 第二节--通过Intent实现Activity的跳转
- 通过ssh通道实现linux登陆远程linux桌面
- 使用vi编辑binary文件
- VC2010 如何根据ID查找Ribbon的元素
- ThinkPHP 安全
- 提高 Web Service 数据传输效率的基本方法
- Android传感器之加速度传感器
- 通过Intent实现返回桌面
- 配置 vim 为php开发工具
- delphli js unicode
- C/C++中计算程序运行时间
- Swing 事件模型
- 快速排序
- 打开共享之门成就成功之路
- 解决Windows 2008驱动安装失败
- Android传感器之距离传感器