提交 f7a565bd 编写于 作者: 门心叼龙's avatar 门心叼龙

code perfecty

上级 0f01e5df
......@@ -12,7 +12,13 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".WindowManagerActivity"></activity>
<service
android:name=".service.TestService1"
android:enabled="true"
android:exported="true"></service>
<activity android:name=".TestServiceActivity" />
<activity android:name=".WindowManagerActivity" />
<activity android:name=".test.view1.SticyLayout2Activity" />
<activity android:name=".test.view1.ExpandableListView2Activity" />
<activity android:name=".test.view1.ViewPagerTest2Activity" />
......@@ -36,6 +42,8 @@
</activity>
<activity android:name=".StickyLayoutActivity" />
<activity android:name=".HorizontalScrollViewExActivity" />
<service android:name=".service.TestService" />
</application>
</manifest>
\ No newline at end of file
// IMyAidlInterface.aidl
package com.mxdl.customview;
// Declare any non-default types here with import statements
interface IMyAidlInterface {
/**
* Demonstrates some basic types that you can use as parameters
* and return values in AIDL.
*/
void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat,
double aDouble, String aString);
void test(String name);
String test1(String name);
}
package com.mxdl.customview;
import android.app.Service;
import android.content.Intent;
import androidx.appcompat.app.AppCompatActivity;
......@@ -27,6 +28,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private Button mBtnCaptrueView;
private Button mBtnCricleCapture;
private Button mBtnRectCapture;
private Button mBtnService;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -38,6 +40,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
mBtnCaptrueView = findViewById(R.id.btn_capture_square);
mBtnCricleCapture = findViewById(R.id.btn_capture_cricle);
mBtnRectCapture = findViewById(R.id.btn_capture_rect);
mBtnService = findViewById(R.id.btn_service);
mBtnStickyLayout.setOnClickListener(this);
mBtnHorizontalScrollViewEx.setOnClickListener(this);
......@@ -45,6 +48,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
mBtnCaptrueView.setOnClickListener(this);
mBtnCricleCapture.setOnClickListener(this);
mBtnRectCapture.setOnClickListener(this);
mBtnService.setOnClickListener(this);
}
......@@ -69,6 +73,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
case R.id.btn_capture_cricle:
startActivity(new Intent(this, CaptureCricleViewActivity.class));
break;
case R.id.btn_service:
startActivity(new Intent(this, TestServiceActivity.class));
break;
}
......
package com.mxdl.customview;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import android.view.View;
import com.mxdl.customview.service.IMyService;
import com.mxdl.customview.service.TestService;
import com.mxdl.customview.service.TestService1;
public class TestServiceActivity extends AppCompatActivity {
private IMyAidlInterface mMyService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test_service);
findViewById(R.id.btn_bind_service).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
bindService();
}
});
}
private void bindService() {
bindService(new Intent(TestServiceActivity.this, TestService1.class), new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mMyService = IMyAidlInterface.Stub.asInterface(service);
//mMyService = (IMyAidlInterface) service;
Log.v("MYTAG","onServiceConnected succ");
try {
String result = mMyService.test1("fafafa");
Log.v("MYTAG",result);
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
}, Context.BIND_AUTO_CREATE);
}
}
package com.mxdl.customview.service;
/**
* Description: <IMyService><br>
* Author: mxdl<br>
* Date: 2019/11/13<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public interface IMyService {
void test();
}
package com.mxdl.customview.service;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import androidx.annotation.Nullable;
/**
* Description: <TestService><br>
* Author: mxdl<br>
* Date: 2019/11/13<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public class TestService extends Service{
MyService bind;
@Override
public void onCreate() {
bind = new MyService();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return bind;
}
class MyService extends Binder implements IMyService{
@Override
public void test() {
Log.v("MYTAG","hello world...");
}
}
}
package com.mxdl.customview.service;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.mxdl.customview.IMyAidlInterface;
public class TestService1 extends Service {
MyService binder;
@Override
public void onCreate() {
Log.v("MYTAG","onCreate");
binder = new MyService();
}
public TestService1() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.v("MYTAG","onStartCommand");
return super.onStartCommand(intent, flags, startId);
}
@Override
public IBinder onBind(Intent intent) {
Log.v("MYTAG","onBind");
return binder;
}
class MyService extends IMyAidlInterface.Stub{
@Override
public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {
}
@Override
public void test(String name) throws RemoteException {
}
@Override
public String test1(String name) throws RemoteException {
return "hahaha:"+name;
}
}
}
......@@ -49,5 +49,12 @@
android:layout_height="wrap_content"
android:text="CaptureCricleView"
android:textAllCaps="false" />
<Button
android:id="@+id/btn_service"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TestService"
android:textAllCaps="false" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android" >
<Button
android:id="@+id/btn_bind_service"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="绑定服务"
/>
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册