函數StartRecord(int requestCode, int resultCode, Intent data)
在RecordService.cs
需要一個參數Intent數據,我不知道如何將意圖參數傳遞給myIntent,並在另一個意圖中檢索意圖參數。如何使用其他意圖傳遞意圖數據?
你能幫我嗎?謝謝!
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != MPublicPar.PERMISSION_CODE) {
Log.e("Mycwcgr", "Unknown request code: " + requestCode);
return;
}
if (resultCode != RESULT_OK) {
Toast.makeText(this, "Screen Cast Permission Denied", Toast.LENGTH_SHORT).show();
return;
}
Intent myIntent = new Intent(mContext,bll.RecordService.class);
myIntent.putExtra("requestCode", requestCode);
myIntent.putExtra("resultCode",resultCode);
//How to pass Intent data
startService(myIntent);
}
RecordService.cs
public class RecordService extends Service {
private Handler handler;
private RecordHelper mRecordHelper;
private MPublicPar.RecordArg mRecordArg;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onCreate(){
handler = new Handler();
...
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
int requestCode=intent.getIntExtra("requestCode",0);
int resultCode=intent.getIntExtra("resultCode",0);
////How to retrieve Intent data
StartRecord(requestCode, resultCode, mydata);
return super.onStartCommand(intent, flags, startId);
}
public void StartRecord(int requestCode, int resultCode, Intent data){
prepareRecorder();
mMediaProjection = mProjectionManager.getMediaProjection(resultCode, data);
MediaProjectionCallback mMediaProjectionCallback = new MediaProjectionCallback();
mMediaProjection.registerCallback(mMediaProjectionCallback, null);
mVirtualDisplay=createVirtualDisplay();
mMediaRecorder.start();
}
}
可能的重複[如何在Android中的活動之間傳遞數據?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android ) – starkshang