aidl 实现远程服务调用 及 回调
来源:互联网 发布:php post 实现 get 编辑:程序博客网 时间:2024/06/01 09:37
package com.junnet.heepay.service;
import java.util.Map;
import com.junnet.heepay.activity.LoginActivity;
import com.junnet.heepay.util.PayInfo;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;
public class HeepayService extends Service {
private static String TAG = "HeepayService";
private static RemoteCallbackList<IRemoteServiceCallback> callbacks = new RemoteCallbackList<IRemoteServiceCallback>();
public final IRemoteHeepayService.Stub mBinder = new IRemoteHeepayService.Stub() {
// 去支付
@Override
public String goToPay(Bundle payInfo) throws RemoteException {
PayInfo.payinfo = payInfo;
// 首先得登录
System.out.println("goToPay");
Intent intent = new Intent();
intent.setAction("com.junnet.heepay.activity.LoginActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(getApplicationContext(), LoginActivity.class);
// intent.putExtra("payinfo", bundle);
HeepayService.this.startActivity(intent);
// callbacks.getBroadcastItem(0).startActivity("com.junnet.business",
// "com.junnet.business.MainActivity", returnBundle());
// Log.e(TAG, "startActivity");
return "成功";
}
@Override
public void registerCallback(IRemoteServiceCallback callback)
throws RemoteException {
callbacks.register(callback);
}
@Override
public void unregisterCallback(IRemoteServiceCallback callback)
throws RemoteException {
callbacks.unregister(callback);
}
};
@Override
public IBinder onBind(Intent intent) {
Log.i(TAG, "success in onBind");
return mBinder;
}
public void onCreate() {
printf("service on create");
super.onCreate();
};
@Override
public void onDestroy() {
printf("service on destroy");
super.onDestroy();
}
@Override
public boolean onUnbind(Intent intent) {
printf("service on unbind");
return super.onUnbind(intent);
}
public void onRebind(Intent intent) {
printf("service on rebind");
super.onRebind(intent);
}
private void printf(String str) {
Log.v(TAG, "###################------ " + str + "------");
}
private Bundle returnBundle() {
Bundle bundle = new Bundle();
bundle.putString("bundle", "bundle");
return bundle;
}
// 回调方法
public static void callBack(String packageName, String activityName, Bundle data) {
int n = callbacks.beginBroadcast();
Log.i(TAG, "mCallbacks.beginBroadcast() is " + n);
try {
for (int i = 0; i < n; i++) {
System.out.println("~~callBack~~");
callbacks.getBroadcastItem(i).startActivity(packageName,
activityName, data);
callbacks.unregister(callbacks.getBroadcastItem(i));
}
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
callbacks.finishBroadcast();
}
}
import java.util.Map;
import com.junnet.heepay.activity.LoginActivity;
import com.junnet.heepay.util.PayInfo;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;
public class HeepayService extends Service {
private static String TAG = "HeepayService";
private static RemoteCallbackList<IRemoteServiceCallback> callbacks = new RemoteCallbackList<IRemoteServiceCallback>();
public final IRemoteHeepayService.Stub mBinder = new IRemoteHeepayService.Stub() {
// 去支付
@Override
public String goToPay(Bundle payInfo) throws RemoteException {
PayInfo.payinfo = payInfo;
// 首先得登录
System.out.println("goToPay");
Intent intent = new Intent();
intent.setAction("com.junnet.heepay.activity.LoginActivity");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClass(getApplicationContext(), LoginActivity.class);
// intent.putExtra("payinfo", bundle);
HeepayService.this.startActivity(intent);
// callbacks.getBroadcastItem(0).startActivity("com.junnet.business",
// "com.junnet.business.MainActivity", returnBundle());
// Log.e(TAG, "startActivity");
return "成功";
}
@Override
public void registerCallback(IRemoteServiceCallback callback)
throws RemoteException {
callbacks.register(callback);
}
@Override
public void unregisterCallback(IRemoteServiceCallback callback)
throws RemoteException {
callbacks.unregister(callback);
}
};
@Override
public IBinder onBind(Intent intent) {
Log.i(TAG, "success in onBind");
return mBinder;
}
public void onCreate() {
printf("service on create");
super.onCreate();
};
@Override
public void onDestroy() {
printf("service on destroy");
super.onDestroy();
}
@Override
public boolean onUnbind(Intent intent) {
printf("service on unbind");
return super.onUnbind(intent);
}
public void onRebind(Intent intent) {
printf("service on rebind");
super.onRebind(intent);
}
private void printf(String str) {
Log.v(TAG, "###################------ " + str + "------");
}
private Bundle returnBundle() {
Bundle bundle = new Bundle();
bundle.putString("bundle", "bundle");
return bundle;
}
// 回调方法
public static void callBack(String packageName, String activityName, Bundle data) {
int n = callbacks.beginBroadcast();
Log.i(TAG, "mCallbacks.beginBroadcast() is " + n);
try {
for (int i = 0; i < n; i++) {
System.out.println("~~callBack~~");
callbacks.getBroadcastItem(i).startActivity(packageName,
activityName, data);
callbacks.unregister(callbacks.getBroadcastItem(i));
}
} catch (RemoteException e) {
Log.e(TAG, "", e);
}
callbacks.finishBroadcast();
}
}
- aidl 实现远程服务调用 及 回调
- aidl远程服务调用
- AIDL实现远程服务
- 采用AIDL调用远程服务
- 在Android Studio中实现AIDL远程服务调用
- Android AIDL实现远程服务
- Android中使用AIDL调用远程服务
- android-------采用AIDL调用远程服务
- android,aidl,绑定远程服务,调用远程服务的方法
- Android远程服务一:android AIDL远程服务调用
- Android studio 使用aidl实现远程服务
- 使用AIDL实现IPC通信之——简单调用远程服务的方法
- AIDL实现远程调用的小例子
- AIDL实现跨应用调用服务
- Android service aidl 远程服务调用播放器实例
- AIDL绑定远程服务
- aidl绑定远程服务
- Service (aidl远程服务)
- PLD -Verilog语言中wire与reg的区别
- androidの开机自启动程序
- rails 安装出错
- jQuery中调用WebService方法小结
- VC实现flash透明显示
- aidl 实现远程服务调用 及 回调
- 常用正则表达式
- 小妞会装机 -- 一个装机软件的开发笔记( 三)
- jQuery Ajax方法调用 Asp.Net WebService 的详细实例代码
- JXL 生成EXCEL文件格式说明
- Java获取泛型参数的类型的方法 .
- 回顾MySpace架构的坎坷之路
- LM3S LWIP的一个配置文件2
- hbase表操作优化