2

The function StartRecord(int requestCode, int resultCode, Intent data) in RecordService.cs need a parameter Intent data, I don't know how to pass the intent par to myIntent, and retrieve the intent par in another intent.

Could you help me ? Thanks!

 @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();
    }



}
HelloCW
  • 843
  • 22
  • 125
  • 310
  • Possible duplicate of [How do I pass data between activities in Android?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android) – starkshang Nov 05 '15 at 05:11

2 Answers2

0

Instead of passing the first Intent data you can create a new intent and get all the extras from the first one

Intent myIntent = new Intent(mContext,bll.RecordService.class);
myIntent.putExtras(data.getExtras());

// Add additional extras if you need to
myIntent.putExtra(...,...);
Mark Pazon
  • 6,167
  • 2
  • 34
  • 50
  • Thanks! but how can I get the Intent? For normal par, I can use int resultCode=intent.getIntExtra("resultCode",0); – HelloCW Nov 05 '15 at 06:09
  • What would you use the original intent for? You can get the information from the original intent and then create a new one and pass the new one instead. – Mark Pazon Nov 05 '15 at 08:41
  • Thanks! I need pass a original intent , I think mMediaProjection = mProjectionManager.getMediaProjection(resultCode, data) need original intent – HelloCW Nov 05 '15 at 09:47
0

Instead of passing an intent object you can pass relevant data that you want to retrieve there in the next activity

Intent myIntent = new Intent(mContext,bll.RecordService.class);

    myIntent.putExtra("requestCode", requestCode);
    myIntent.putExtra("resultCode",resultCode);
    myIntent.putExtra("intentData", data.getExtras());

    // or if you have some integer data in your data object or any other data you can simply 
    // pass that data rather than passing intent data

    startService(myIntent);
Zubair Akber
  • 2,760
  • 13
  • 30