phonetest

package com.hyf.service;

 

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

 

 

public class RecordisBootReciever extends BroadcastReceiver {

    public static int shutdowntimes;

    public static int startuptimes;

private static final String TAG="RecordShutdownTimes";

@Override

public void onReceive(Context context, Intent intent) {

// TODO Auto-generated method stub

if("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())){

startuptimes++;

}

shutdowntimes=(shutdowntimes==0)?0:startuptimes-1;

}

 

}

------------------------------------------------------------------

 

package com.hyf.test;

 

import com.hyf.service.RecordisBootReciever;

 

import android.app.Activity;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.TextView;

 

public class ShutDownTimesActivity extends Activity {

private TextView startuptimes;

private TextView shutdowntimes;

Button startuptimesButton;

Button shutdowntimesButton;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        startuptimesButton=(Button)findViewById(R.id.startuptimesButton);

        shutdowntimesButton =(Button)findViewById(R.id.shutdowntimesButton);

        startuptimes= (TextView)findViewById(R.id.startuptimes);

        shutdowntimes=(TextView)findViewById(R.id.shutdowntimes);

        startuptimesButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

// TODO Auto-generated method stub

startuptimes.setText(RecordisBootReciever.startuptimes);

setContentView(R.layout.main);

}

});

        shutdowntimesButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

// TODO Auto-generated method stub

shutdowntimes.setText(RecordisBootReciever.shutdowntimes);

setContentView(R.layout.main);

}

});

    }

}

 

---------------------

<?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"

    >

<LinearLayout

   android:orientation="horizontal"

   android:layout_width="fill_parent"

   android:layout_height="fill_parent"

   android:layout_weight="1"

   >

    <Button

       android:id="@+id/startuptimesButton"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:text="@string/startuptimesButton"

       />

   <TextView

       android:id="@+id/startuptimes"

       android:layout_width="150dip"

       android:layout_height="wrap_content"

       android:background="#aaaa00"

  />

</LinearLayout>      

<LinearLayout

   android:orientation="horizontal"

   android:layout_width="fill_parent"

   android:layout_height="fill_parent"

   android:layout_weight="1"

   >

    <Button

       android:id="@+id/shutdowntimesButton"

       android:layout_width="wrap_content"

       android:layout_height="wrap_content"

       android:text="@string/shutdowntimesButton"

       />

   <TextView

       android:id="@+id/shutdowntimes"

       android:layout_width="150dip"

       android:layout_height="wrap_content"

       android:background="#aaaa00"

       />

</LinearLayout>        

</LinearLayout>

----------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.huawei.test"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".ShutDownTimesActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <receiver android:name=".RecordisBootReciever">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>
        </receiver>
    </application>
    <uses-sdk android:minSdkVersion="8" />
</manifest> 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值