Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to send data in service based android app
    primarykey
    data
    text
    <p>I want to send data from one application A to other application B using AIDL file. My appl A is like below,</p> <pre><code>public class LibValue { public static native int intFromJNI(int n); static { System.loadLibrary("hello"); System.out.println("LibValue : Loading library"); } </code></pre> <p>I am getting value from JNI file to above class. The data from above class to send another app B using AIDL service is like below.</p> <pre><code>IEventService.aidl interface IEventService { int intFromJNI(in int n); } </code></pre> <p>for this I written IEventImpl.java class </p> <pre><code> public class IEventImpl extends IEventService.Stub{ int result; @Override public int intFromJNI(int n) throws RemoteException { // TODO Auto-generated method stub System.out.println("IEventImpl"+LibValue.intFromJNI(n)); return LibValue.intFromJNI(n); } } </code></pre> <p>To access above class I writtn service class like below</p> <p>public class EventService extends Service {</p> <pre><code>public IEventImpl iservice; @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub Log.i("EventService", "indside onBind"); return this.iservice; } @Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); this.iservice = new IEventImpl(); Log.i("EventService", "indside OncREATE"); } @Override public boolean onUnbind(Intent intent) { // TODO Auto-generated method stub return super.onUnbind(intent); } @Override public void onDestroy() { // TODO Auto-generated method stub this.iservice = null; super.onDestroy(); } </code></pre> <p>All above classes are server side. The below class is Client(app) class to access data.</p> <pre><code>public class EventClient extends Activity implements OnClickListener, ServiceConnection{ public IEventService myService; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_event_client); button = (Button)findViewById(R.id.button1); this.button.setOnClickListener(this); } @Override protected void onResume() { // TODO Auto-generated method stub super.onResume(); if (!super.bindService(new Intent(IEventService.class.getName()), this, BIND_AUTO_CREATE)) { Log.w("EventClient", "Failed to bind to service"); System.out.println("inside on resume"); } } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); super.unbindService(this); } @Override public void onServiceConnected(ComponentName name, IBinder service) { // TODO Auto-generated method stub this.myService = IEventService.Stub.asInterface(service); Log.i("EventClient", "ServiceConnected"); } @Override public void onServiceDisconnected(ComponentName name) { // TODO Auto-generated method stub Log.d("EventClient", "onServiceDisconnected()'ed to " + name); // our IFibonacciService service is no longer connected this.myService = null; } </code></pre> <p>I am trying to access data from service class but not able to find out the way. can anybody tell how to access data from service to client application ?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload