package com.example.stone.listviewdemo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import com.example.stone.listviewdemo.aidl.IMyAidlInterface;
import com.example.stone.listviewdemo.aidl.IRemoteCallback;
import com.example.stone.listviewdemo.services.HostService;
import javax.security.auth.login.LoginException;
public class MainActivity extends AppCompatActivity {
private IMyAidlInterface mAidlInterface;
private ServiceConnection mConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Log.d(TAG, "Get iBinder done: " + iBinder);
mAidlInterface = IMyAidlInterface.Stub.asInterface(iBinder);
try {
mAidlInterface.basicTypes(10, 123456789, true, 2.0f, 3.0f, "Hey man");
int pid = mAidlInterface.getServicePid("This is stone client");
mAidlInterface.registerRemoteCallback(mCallback);
Log.d(TAG, "Host service run with pid = " + pid);
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
if (mAidlInterface != null) {
try {
mAidlInterface.unregisterRemoteCallback(mCallback);
} catch (RemoteException e) {
e.printStackTrace();
}
}
mAidlInterface = null;
}
};
private static final String TAG = "StoneClientActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StoneListView listview = (StoneListView) findViewById(R.id.listview);
listview.setAdapter(new TestArrayAdapter(this));
attachToHost();
}
private void attachToHost() {
Intent intent = new Intent(this, HostService.class);
intent.setAction(IMyAidlInterface.class.getName());
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
Log.d(TAG, "attachToHost: bind service");
}
private IRemoteCallback mCallback = new IRemoteCallback.Stub() {
@Override
public void onEvent(String eventName) throws RemoteException {
Log.d(TAG, "onEvent: " + eventName);
}
};
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Remote Service Demo (103个子文件)
IMyAidlInterface.aidl 627B
IMyAidlInterface.aidl 627B
IRemoteCallback.aidl 208B
IRemoteCallback.aidl 208B
gradlew.bat 2KB
gradlew.bat 2KB
fileSnapshots.bin 1.91MB
fileSnapshots.bin 563KB
fileHashes.bin 96KB
fileHashes.bin 95KB
taskArtifacts.bin 85KB
taskArtifacts.bin 48KB
outputFileStates.bin 19KB
outputFileStates.bin 19KB
.gitignore 97B
.gitignore 97B
.gitignore 7B
.gitignore 7B
build.gradle 633B
build.gradle 631B
build.gradle 498B
build.gradle 498B
settings.gradle 15B
settings.gradle 15B
gradlew 5KB
gradlew 5KB
app.iml 7KB
app.iml 7KB
AIDLClientDemo.iml 945B
ListViewDemo.iml 943B
gradle-wrapper.jar 52KB
gradle-wrapper.jar 52KB
MainActivity.java 3KB
HostService.java 3KB
MainActivity.java 3KB
StoneListView.java 2KB
TestArrayAdapter.java 1KB
ApplicationTest.java 363B
ApplicationTest.java 361B
ExampleUnitTest.java 325B
ExampleUnitTest.java 323B
cache.properties.lock 17B
cache.properties.lock 17B
.name 14B
.name 12B
ic_launcher.png 10KB
ic_launcher.png 10KB
ic_launcher.png 8KB
ic_launcher.png 8KB
ic_launcher.png 5KB
ic_launcher.png 5KB
ic_launcher.png 3KB
ic_launcher.png 3KB
ic_launcher.png 2KB
ic_launcher.png 2KB
proguard-rules.pro 705B
proguard-rules.pro 705B
gradle.properties 855B
gradle.properties 855B
local.properties 476B
local.properties 476B
gradle-wrapper.properties 230B
gradle-wrapper.properties 230B
cache.properties 30B
cache.properties 30B
workspace.xml 158KB
workspace.xml 136KB
misc.xml 3KB
misc.xml 3KB
AndroidManifest.xml 1012B
support_v4_23_0_1.xml 948B
appcompat_v7_23_0_1.xml 807B
support_v4_23_0_1.xml 777B
activity_main.xml 745B
activity_main.xml 712B
compiler.xml 686B
compiler.xml 686B
AndroidManifest.xml 673B
appcompat_v7_23_0_1.xml 634B
gradle.xml 608B
gradle.xml 608B
support_annotations_23_0_1.xml 605B
support_annotations_23_0_1.xml 605B
runConfigurations.xml 564B
runConfigurations.xml 564B
list_item.xml 447B
styles.xml 383B
styles.xml 383B
modules.xml 365B
modules.xml 361B
dimens.xml 358B
dimens.xml 358B
dimens.xml 211B
dimens.xml 211B
colors.xml 208B
colors.xml 208B
vcs.xml 164B
vcs.xml 164B
strings.xml 77B
strings.xml 75B
共 103 条
- 1
- 2
资源评论
TechStone
- 粉丝: 29
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功