OK, I found found a way to do it :) Maybe it is not a beautiful one, but it works fine:
Create a service:
import android.app.Service; import android.content.Intent; import android.os.AsyncTask; import android.os.IBinder; public class rtmpdumpService extends Service { @Override public IBinder onBind(Intent intent) { return null; } @Override public void onStart(Intent intent, int startId) { super.onStart(intent, startId); config = this; String extras = ""; if(intent != null){ //Get needed information extras = intent.getExtras().getString("rtmp"); } else { this.stopSelf(); } doWork(extras); } @Override public void onDestroy() { super.onDestroy(); } public void doWork(String rtmp){ //Do work here: for example rtmpdump Rtmpdump dump = new Rtmpdump(); dump.parseString(params[0]); System.exit(0); this.stopSelf(); } }
Register in AndroidManifest as service with these attributes
android:name=".rtmpdumpService" android:exported="false" android:process=":rtmp"
Start service:
Intent rtmpdumpIntent = new Intent(getApplicationContext(), rtmpdumpService.class); eSendIntent.putExtra("rtmp", "RTMP CODE"); startService(rtmpdumpIntent);
Sometimes you have to wait until it finishes:
After the Service is started (startService(rtmpdumpIntent):
do {
try {
Thread.sleep(500);
}
catch (InterruptedException e) {
//Log
}
} while( isServiceRunning(rtmpdumpService.class) == true);
isServiceRunning function:
private boolean isServiceRunning(Class cl) {
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
if (cl.getName().equals(service.service.getClassName())) {
return true;
}
}
return false;
}