2015-11-05 76 views
2

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



} 
+0

可能的重複[如何在Android中的活動之間傳遞數據?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-in-android ) – starkshang

回答

0

而不是經過第一意向數據,你可以創建一個新的意圖,從第一個

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

// Add additional extras if you need to 
myIntent.putExtra(...,...); 
+0

謝謝!但我如何獲得意向?對於正常的par,我可以使用int resultCode = intent.getIntExtra(「resultCode」,0); – HelloCW

+0

你會用什麼原始意圖?您可以從最初的意圖中獲取信息,然後創建一個新的信息並改爲傳遞新信息。 –

+0

謝謝!我需要傳遞一個原始意圖,我認爲mMediaProjection = mProjectionManager.getMediaProjection(resultCode,data)需要原始意圖 – HelloCW

0

而不是讓所有的演員傳遞一個意圖對象,您可以在下一個活動中傳遞您想要檢索的相關數據

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); 
+0

謝謝!但我如何獲得意向?對於正常的par,我可以使用int resultCode = intent.getIntExtra(「resultCode」,0); – HelloCW

+0

intent.putExtra(「intent」,data); 並得到它像意圖intent = intent.getExtra(intent,null); 我還沒有測試過,但希望它能正常工作,試試並更新我 –

+0

謝謝!但我不認爲intent.getExtra(intent,null)可以工作 – HelloCW