sevice based on .aidl

Put your problem here if it does not fit any of the other categories.

sevice based on .aidl

Postby season.xiong » Tue Nov 18, 2008 4:20 am

I wrote a service based on aidl to print some message;
IPrint.aidl was follows:
interface IPrint {
String printLog(in String text);

}
then generate a interface IPrint.java.
PrintService was follows :
public class PrintService extends Service{
String action = "Intent.ACTION_VIEW";
public final IPrint.Stub printBind = new IPrint.Stub(){
public String printLog(String text) {
// TODO Auto-generated method stubr\
try {
Log.i(button.TAG, "service started");
} catch (Exception e) {
Log.i(button.TAG, "service started failed"+e.toString());
}

return null;
}

};
@Override
public IBinder onBind(Intent intent) {
Log.i(button.TAG, "onBind printService");
if(action.equals(intent.getAction())){
return printBind;
}
else return null;
}

}

public class AidlTest extends Activity implements OnClickListener{
@Override
public void onCreate(Bundle bundle){
Log.i(button.TAG, "onCreate");
super.onCreate(bundle);
setContentView(R.layout.main);
Button b = (Button)findViewById(R.id.Button01);
b.setOnClickListener(this);
Intent intent = new Intent(Intent.ACTION_VIEW);

bindService(intent, conn, Context.BIND_AUTO_CREATE);
Log.i(button.TAG, "bind service onResume");
}
IPrint printService;
ServiceConnection conn = new ServiceConnection(){

public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(button.TAG, "onBinde is running");
// TODO Auto-generated method stub
printService = IPrint.Stub.asInterface(service);
}

public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
printService = null;
}

};

public void onClick(View v){
Log.i(button.TAG, "onClick");
try {
printService.printLog("helllo");
Log.i(button.TAG, "onClick");
} catch (RemoteException e) {
Log.i(button.TAG, e.toString());
}
}

}
when the project run on the "printService.printLog("helllo");"
I catch the error, I don't know why.please help me
season.xiong
Freshman
Freshman
 
Posts: 3
Joined: Mon Nov 10, 2008 7:40 am

Top

Postby MrSnowflake » Tue Nov 18, 2008 11:15 am

Did you implement IPrint int the Service, and have you setup a connection to the service? Read your log for more info.
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: MSNbot Media and 18 guests