use of com.ryg.dynamicload.service.ITestServiceInterface in project dynamic-load-apk by singwhatiwanna.
the class MainActivity method generateContentView.
private View generateContentView(final Context context) {
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
layout.setBackgroundColor(Color.parseColor("#F79AB5"));
Button button = new Button(context);
button.setText("Start TestActivity");
layout.addView(button, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DLIntent intent = new DLIntent(getPackageName(), TestFragmentActivity.class);
// 传递Parcelable类型的数据
intent.putExtra("person", new Person("plugin-a", 22));
intent.putExtra("dl_extra", "from DL framework");
startPluginActivityForResult(intent, 0);
}
});
Button button2 = new Button(context);
button2.setText("Start Service");
layout.addView(button2, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
button2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
DLIntent intent = new DLIntent(getPackageName(), TestService.class);
startPluginService(intent);
}
});
Button button3 = new Button(context);
button3.setText("bind Service");
layout.addView(button3, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
button3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mConnecton == null) {
mConnecton = new ServiceConnection() {
public void onServiceDisconnected(ComponentName name) {
}
public void onServiceConnected(ComponentName name, IBinder binder) {
int sum = ((ITestServiceInterface) binder).sum(5, 5);
Log.e("MainActivity", "onServiceConnected sum(5 + 5) = " + sum);
}
};
}
DLIntent intent = new DLIntent(getPackageName(), TestService.class);
bindPluginService(intent, mConnecton, Context.BIND_AUTO_CREATE);
}
});
Button button4 = new Button(context);
button4.setText("unbind Service");
layout.addView(button4, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
button4.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
if (mConnecton != null) {
DLIntent intent = new DLIntent(getPackageName(), TestService.class);
unBindPluginService(intent, mConnecton);
mConnecton = null;
}
}
});
return layout;
}
Aggregations