aidl的使用

接口文件aidl

1
2
3
4
5
6
package com.zst.xposed.halo.floatingwindow3.services;

interface IActivityManagerService {
void snapActivityTop(int id);
void snapActivityBottom(int id);
}

manager

1
2
3
4
5
6
7
8
9
10
11
12
package com.zst.xposed.halo.floatingwindow3.services;
import com.zst.xposed.halo.floatingwindow3.IActivityManagerService;
public class ActivityManager extends IActivityManagerService.Stub {

public ActivityManagerService mService;
public ActivitManager(ActivityManagerService service) {
mService = service;
}

public void snapActivityTop(int id) {}
public void snapActivityBottom(int id) {}
}

service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package com.zst.xposed.halo.floatingwindow3.services;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;

public class ActivityManagerService extends Service {

@Nullable
@Override
public IBinder onBind(Intent intent) {
return new ActivitManager(this);
}
}

client

1
2
3
4
5
6
7
8
9
10
11
12
13
ActivityManager manager = null;
private ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
manager = (ActivityManager)MyAIDLService.Stub.asInterface(service);
manager.snapActivityTop(TOP)
}

@Override
public void onServiceDisconnected(ComponentName name) {
manager = null;
}
};