0
我有兩個活動。 如果我需要將Activity 1的啓動服務的意圖分享給Activity 2以停止服務(因爲onStartCommand()返回START_STICKY因此需要使用相同的意圖停止服務)。我該如何巧妙地去解決它。在兩個活動之間共享實例對象的好方法是什麼?
在活動1
Intent wrapperServiceIntent = new Intent(mContext,BleWrapperService.class);
bindService(wrapperServiceIntent,mBLEWrapperServiceConnection,BIND_AUTO_CREATE);
startService(wrapperServiceIntent);
在活動2
我需要啓動該服務(即wrapperServiceIntent)意圖
stopService(wrapperServiceIntent);
mContext.unbindService(mServiceConnection);
向我們顯示您的代碼。 – dsharew
//通過: intent.putExtra(「MyClass」,obj); //檢索第二個對象的活動 getIntent()。getSerializableExtra(「MyClass」); – Drim
@DegenSharew。檢查代碼 –