【发布时间】:2018-01-16 15:31:42
【问题描述】:
我需要调用 onHandleIntent 并从 app1 接收一个值并在 app2 中获得结果,而无需用户通知(不同的应用程序,一个活动将调用另一个应用程序的服务)。 但是,当 onHandleIntent 在这一行开始时:
mReceiver = workIntent.getParcelableExtra("receiver");
带来错误
E/Parcel: Class not found when unmarshalling: com.example.idscomercial.myapplication.AddressResultReceiver
java.lang.ClassNotFoundException: com.example.idscomercial.myapplication.AddressResultReceiver
...
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.idscomercial.myapplication.AddressResultReceiver" on path: DexPathList[[zip file "/data/app/com.veritran.vttokentest-2/base.apk"],nativeLibraryDirectories=[/data/app/com.veritran.vttokentest-2/lib/arm, /vendor/lib, /system/lib]]
我真的读过:
https://stackoverflow.com/questions/28589509/android-e-parcel-class-not-found-when-unmarshalling-only-on-samsung-tab3
但还是找不到解决办法
这是代码:
应用程序1
public class servicev extends IntentService {
protected ResultReceiver mReceiver;
public servicev() {
super("yeah");
}
@Override
protected void onHandleIntent(Intent workIntent) {
Toast b = Toast.makeText(this.getApplicationContext(), "onHandle starting", Toast.LENGTH_LONG );
b.show();
Log.d("just", "tellme");
String dataString = workIntent.getDataString();
mReceiver = workIntent.getParcelableExtra("receiver");
// mReceiver = new AddressResultReceiver(new Handler());
deliverResultToReceiver(1,"value of servicev");
}
private void deliverResultToReceiver(int resultCode, String message) {
Bundle bundle = new Bundle();
bundle.putString("receiver", message);
mReceiver.send(resultCode, bundle);
}
}
应用程序2:
public class MainActivity extends AppCompatActivity {
protected ResultReceiver mResultReceiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startIntentService();
setContentView(R.layout.activity_main);
}
protected void startIntentService() {
//Intent intent = new Intent();
mResultReceiver = new AddressResultReceiver(new Handler());
Intent intent=new Intent("com.veritran.vttokentest.servicev.START_SERVICE");
intent.setPackage("com.veritran.vttokentest");
//Intent intent = new Intent(this, FetchAddressIntentService.class);
intent.putExtra("receiver", mResultReceiver);
startService(intent);
}
}
==> 2
public
class AddressResultReceiver extends ResultReceiver {
public AddressResultReceiver(Handler handler) {
super(handler);
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
int duration = Toast.LENGTH_LONG;
String mAddressOutput = resultData.getString("1");
//Toast toast = Toast.makeText(context, "hi brow", duration);
//toast.show();
if (resultCode == 1) {
}
}
}
清单 app1:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.veritran.vttokentest">
<application
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.veritran.vttokentest.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:enabled="true"
android:exported="true"
android:name="com.veritran.vttokentest.servicev">
<intent-filter>
<action android:name="com.veritran.vttokentest.servicev.START_SERVICE" />
</intent-filter>
</service>
</application>
</manifest>
【问题讨论】:
标签: android android-intent service