AActivity类
package com.example.xunlianchang;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.ComponentName;
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 android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SeekBar;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class AActivity extends AppCompatActivity {
TextView textView0,textView1,textView2,textView3;
ImageView textView;
private MyServiceConnection myServiceConnection = new MyServiceConnection();
private Bean b;
Intent intent;
private Button button;
AIDLcallbackInterface aidLcallbackInterface;
private ObjectAnimator mProgressAnimator;
private Animation aaa;
private SeekBar mSeekBar;
private static final int PROGRESS_MIN = 0;
private static final int PROGRESS_MAX = 1000;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aaaa);
mSeekBar = findViewById(R.id.prediction_seek_bar);
textView0 = findViewById(R.id.a1);
textView1 = findViewById(R.id.a2);
textView2 = findViewById(R.id.a3);
textView3 = findViewById(R.id.a4);
textView = findViewById(R.id.a5);
button = findViewById(R.id.bt1);
aaa = AnimationUtils.loadAnimation(this, R.anim.xlist_progress);
textView.setAnimation(aaa); //为控件设置动画
aaa.setFillAfter(true); //停留在结束位置
aaa.setFillEnabled(true);
aaa.startNow();
Object object = ((MyApplication)getApplicationContext()).getHashmap().get("aaaa");
if (object instanceof Bean){
b = (Bean) object;
textView0.setText(b.getA()+"");
textView1.setText(b.getB()+"");
textView2.setText(b.getC()+"");
textView3.setText(b.getE()+"");
}
button.setonClickListener(new View.onClickListener() {
@Override
public void onClick(View v) {
textView.startAnimation(aaa);
}
});
textView0.setonClickListener(new View.onClickListener() {
@Override
public void onClick(View v) {
intent = new Intent();
//由于是隐式启动Service 所以要添加对应的action,A和之前服务端的一样。
intent.setAction("com.aaa.hello");
//android 5.0以后直设置action不能启动相应的服务,需要设置packageName或者Component。
intent.setPackage("com.example.xunlianchang"); //packageName 需要和服务端的一致.
bindService(intent,myServiceConnection,BIND_AUTO_CREATE);
}
});
mProgressAnimator = ObjectAnimator.ofInt(mSeekBar, "progress", PROGRESS_MIN, PROGRESS_MAX);
mProgressAnimator.setDuration(5000);
mProgressAnimator.setRepeatCount(0);
mProgressAnimator.setInterpolator(new LinearInterpolator());
mProgressAnimator.start();
mProgressAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int currentValue = (Integer) animation.getAnimatedValue();
Log.e("aaaaaaaaaa",currentValue+"");
}
});
}
private IMyAidlInterface.Stub iMyAidlInterface = new IMyAidlInterface.Stub() {
@Override
public void getInt(int a) throws RemoteException {
Log.e("aaaaa",a+"");
}
};
class MyServiceConnection implements ServiceConnection{
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
aidLcallbackInterface = AIDLcallbackInterface.Stub.asInterface(service);
try {
aidLcallbackInterface.BeanCallback(b);
aidLcallbackInterface.rescart(iMyAidlInterface);
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
}
}
RemoteService类
public class RemoteService extends Service {
private IMyAidlInterface i;
@Override
public void onCreate() {
super.onCreate();
}
private AIDLcallbackInterface.Stub aidLcallbackInterface = new AIDLcallbackInterface.Stub() {
@Override
public void BeanCallback(Bean bean) throws RemoteException {
}
@Override
public void rescart(IMyAidlInterface i) throws RemoteException {
RemoteService.this.i = i;
i.getInt(1);
}
};
@Nullable
@Override
public IBinder onBind(Intent intent) {
Log.d("RemoteService","远程服务绑定成功");
return aidLcallbackInterface;
}
}
AIDLcallbackInterface类
package com.example.xunlianchang;
import com.example.xunlianchang.Bean;
import com.example.xunlianchang.IMyAidlInterface;
// Declare any non-default types here with import statements
interface AIDLcallbackInterface {
void BeanCallback(in Bean bean);
void rescart(IMyAidlInterface i);
}
IMyAidlInterface类
// IMyAidlInterface.aidl
package com.example.xunlianchang;
// Declare any non-default types here with import statements
interface IMyAidlInterface {
void getInt(int a);
}
Bean
package com.example.xunlianchang; parcelable Bean;



