第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

空指針異常

空指針的問題咋解決,我換了action方式也不行.startService取不到服務(wù)器里面的Service類 startService(new Intent(this,Class.forName("aidl.msd.com.aidldemo.AidlService")));像這樣也不行

正在回答

2 回答

另外服務(wù)端要注冊服務(wù),并且允許遠(yuǎn)程,不然會發(fā)生安全性異常

<service android:name=".MService"
? ? ? ? android:process=":remote"
? ? ? ? android:exported="true"
? ?/>

2 回復(fù) 有任何疑惑可以回復(fù)我~

package com.jin.myapplication;

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.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.jin.appspare.AidlObj;
import com.jin.appspare.IMyAidlInterface;
import com.jin.appspare.Person;

import java.util.List;

public class MainActivity extends AppCompatActivity {

? ?private EditText mEt1;
? ?private EditText mEt2;
? ?private TextView mTv;
? ?private Button mBt;
? ?private IMyAidlInterface iMyAidlInterface;
? ?private AidlObj aidlObj;
? ?private ServiceConnection conn = new ServiceConnection() {
? ? ? ?@Override
? ? ? ?public void onServiceConnected(ComponentName name, IBinder service) {
? ? ? ? ? ?Log.e("client", "服務(wù)已經(jīng)連接" + name);
? ? ? ? ? ?//拿到遠(yuǎn)程的服務(wù)-----------------------------------------------
// ? ? ? ? ? ?iMyAidlInterface = IMyAidlInterface.Stub.asInterface(service);
? ? ? ? ? ?aidlObj = AidlObj.Stub.asInterface(service);
? ? ? ?}

? ? ? ?@Override
? ? ? ?public void onServiceDisconnected(ComponentName name) {
? ? ? ? ? ?Log.e("client", "服務(wù)已經(jīng)斷開" + name);
? ? ? ? ? ?aidlObj = null;
? ? ? ?}
? ?};

? ?@Override
? ?protected void onCreate(Bundle savedInstanceState) {
? ? ? ?super.onCreate(savedInstanceState);
? ? ? ?setContentView(R.layout.activity_main);

? ? ? ?initView();
? ? ? ?bindService();
? ? ? ?initEvent();

? ?}

? ?private void initView() {
? ? ? ?mEt1 = (EditText) findViewById(R.id.editText);
? ? ? ?mEt2 = (EditText) findViewById(R.id.editText2);
? ? ? ?mTv = (TextView) findViewById(R.id.textView);
? ? ? ?mBt = (Button) findViewById(R.id.button);


? ?}

? ?private void initEvent() {
? ? ? ?mBt.setOnClickListener(new View.OnClickListener() {
? ? ? ? ? ?@Override
? ? ? ? ? ?public void onClick(View v) {
// ? ? ? ? ? ? ? ?try {
// ? ? ? ? ? ? ? ? ? ?int number1 = Integer.parseInt(mEt1.getText().toString());
// ? ? ? ? ? ? ? ? ? ?int number2 = Integer.parseInt(mEt2.getText().toString());
// ? ? ? ? ? ? ? ? ? ?int add = iMyAidlInterface.add(number1, number2);
// ? ? ? ? ? ? ? ? ? ?mTv.setText(add + "");
// ? ? ? ? ? ? ? ?}catch (Exception e) {
// ? ? ? ? ? ? ? ? ? ?e.printStackTrace();
// ? ? ? ? ? ? ? ?}


? ? ? ? ? ? ? ?try {

????????????????//---------------------------------------------------------------------

? ? ? ? ? ? ? ? ?? List<Person> abc = aidlObj.add(new Person("ABC", 20));
? ? ? ? ? ? ? ? ? ?for (Person person : abc) {
? ? ? ? ? ? ? ? ? ? ? ?Log.e("person-name", person.getName());
? ? ? ? ? ? ? ? ? ? ? ?Log.e("person-age", person.getAge() + "");
? ? ? ? ? ? ? ? ? ?}

????????????//---------------------------------------------------------------------

? ? ? ? ? ? ?? } catch (RemoteException e) {
? ? ? ? ? ? ? ? ? ?e.printStackTrace();
? ? ? ? ? ? ? ?}

? ? ? ? ? ?}
? ? ? ?});
? ?}


? ?private void bindService() {
? ? ? ?//獲取服務(wù)端
? ? ? ?Intent intent = new Intent();
? ? ? ?//顯示Intent啟動綁定服務(wù)
? ? ? ?intent.setComponent(new ComponentName("com.jin.appspare","com.jin.appspare.MService"));
? ? ? ?//一綁定,就會啟動
? ? ? ?Log.e("client","開始綁定服務(wù)端");
? ? ? ?bindService(intent, conn, Context.BIND_AUTO_CREATE);
? ?}

? ?@Override
? ?protected void onDestroy() {
? ? ? ?super.onDestroy();
? ? ? ?unbindService(conn);
? ?}
}

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕姐1217228 提問者

我試下看,你的可以么
2018-03-07 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
AIDL-小白成長記
  • 參與學(xué)習(xí)       42639    人
  • 解答問題       59    個

AIDL-小白成長記,想要快速入門,看本次的教程就對了

進(jìn)入課程
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號