赞
踩
通过对BroadcastReceiver的继承,实现从前台传递两个数到后台计算完成后传回前台。从前台onCreate方法中传送数据过去,再在onReceive方法接收后台返回的数据并且通过handler传回主线程再显示,实现图为:
前台java代码为:
- package com.pangbao.PangIntentService;
-
- import java.util.Random;
-
-
- import android.app.Activity;
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.util.Log;
- import android.widget.TextView;
- import android.widget.Toast;
-
- public class MainActivity extends Activity {
- Handler handler=null;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- TextView tvA=(TextView) findViewById(R.id.tv_a_id);
- TextView tvB=(Tex
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。