Hey guys, please tell me what i'm doing wrong, because this code doesnot bind correctly the service. If i started calling startService works OK.
Manifest.xml: <service android:name=".Service.NotifyInfoUser" android:process=":remote"> <intent-filter> <action android:name="com.mot.oma.Service.INotifyUserRemote" /> </intent-filter> </service> INotifyUserRemote.aidl interface INotifyUserRemote { void notifyUser(in String text, in int flag); } NotifyInfoUser.java package com.oma.Service; import com.oma.R; import com.oma.Activity.PttMain; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.widget.Toast; public class NotifyInfoUser extends Service { private NotificationManager mNM; private static int MOOD_NOTIFICATIONS = R.layout.main; // variable which controls the notification thread @Override public void onCreate() { mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Thread notify_service_thread = new Thread(null, mThread, "NotifyInfoUser"); notify_service_thread.start(); } /** * The function that runs in our worker thread */ Runnable mThread = new Runnable() { public void run() { showNotification(R.drawable.online_connected, "Connected"); } }; private void showNotification(int moodId, CharSequence text) { Notification notification = new Notification(moodId, "Client Started", System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this // notification PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(this, PttMain.class), 0); // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, null, text, contentIntent); // Send the notification. // We use a layout id because it is a unique number. We use it later to // cancel. mNM.notify(MOOD_NOTIFICATIONS, notification); } private final INotifyUserRemote.Stub mBinder = new INotifyUserRemote.Stub() { @Override public void notifyUser(String text, int flag) { // Notify in User's screen Toast.makeText(NotifyInfoUser.this, text, flag).show(); } }; @Override public void onDestroy() { // Cancel the persistent notification. mNM.cancel(MOOD_NOTIFICATIONS); // Notify in User's screen Toast.makeText(this, R.string.ptt_client_stoped, Toast.LENGTH_SHORT).show(); } @Override public IBinder onBind(Intent intent) { return mBinder; } } Activity that starts this service: package com.oma.Activity; import com.oma.R; import com.oma.Service.INotifyUserRemote; import com.oma.Service.INotifyUserRemote.Stub; import android.app.Activity; 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.view.View; import android.view.View.OnClickListener; import android.widget.Toast; import android.widget.ToggleButton; public class StartService extends Activity { ToggleButton button_start_stop; static boolean isClientConnected = false; // Remote service declared by AIDL INotifyUserRemote mService = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.start_stop_service); button_start_stop = (ToggleButton) findViewById(R.id.stop_client); button_start_stop.setChecked(isClientConnected); // Watch for button clicks. button_start_stop.setOnClickListener(mStopClientListener); } @Override protected void onRestart() { super.onRestart(); button_start_stop.setChecked(isClientConnected); } @Override protected void onResume() { super.onResume(); button_start_stop.setChecked(isClientConnected); } // handle button click private OnClickListener mStopClientListener = new OnClickListener() { public void onClick(View v) { boolean isConnected; int i = 0; isClientConnected ^= true; if (isClientConnected) { // Bind Service String action = INotifyUserRemote.class.getName(); isConnected = bindService(new Intent(action), mConn, Context.BIND_AUTO_CREATE); i++; // just for debugging isConnected } else { unbindService(mConn); } } }; private ServiceConnection mConn = new ServiceConnection() { public void onServiceConnected(ComponentName arg0, IBinder arg1) { mService = INotifyUserRemote.Stub.asInterface(arg1); try { mService.notifyUser("Connecting to Client", Toast.LENGTH_LONG); } catch (Exception e) { Toast.makeText(StartService.this, "Failled Calling Remote Service", Toast.LENGTH_LONG) .show(); } } public void onServiceDisconnected(ComponentName name) { mService = null; Toast.makeText(StartService.this, "Remote Service Disconnected", Toast.LENGTH_LONG).show(); } }; } I omitted the other parts in Manifest, that i believe doesn't interfer in this process binding. The program does not have any compiling issue. And, logcat is returning "Binding to a unknow [EMAIL PROTECTED]" Thanks a lot, regards Breno --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---