Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6332945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:22:14+00:00 2026-05-24T18:22:14+00:00

I have an activity in package A (SignerClient), and a service in package B

  • 0

I have an activity in package A (SignerClient), and a service in package B (MyService)

The activity’s resultreceiver:

private ResultReceiver resultreceiver = new ResultReceiver(null) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
            ...
            }
        };

Starting the service:

Intent intent = new Intent("com.example.STARTSERVICE");
intent.putExtra("resultreceiver", resultreceiver);            
startService(intent);

Receiving end:

 ResultReceiver rr = (ResultReceiver) intent.getParcelableExtra("resultreceiver");

Doing this when client and server are in the same package works fine. But in this case i get:

FATAL EXCEPTION: IntentService[MyService]
android.os.BadParcelableException: ClassNotFoundException when unmarshalling: com.example.cryptoclient.SignerClient$1
at android.os.Parcel.readParcelable(Parcel.java:1883)
at android.os.Parcel.readValue(Parcel.java:1771)
at android.os.Parcel.readMapInternal(Parcel.java:2008)
at android.os.Bundle.unparcel(Bundle.java:208)
at android.os.Bundle.getParcelable(Bundle.java:1100)
at android.content.Intent.getParcelableExtra(Intent.java:3396)
at org.axades.service.MyService.onHandleIntent(MyService.java:28)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:59)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.os.HandlerThread.run(HandlerThread.java:60)

What am I missing? Is my idea even possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T18:22:14+00:00Added an answer on May 24, 2026 at 6:22 pm

    Yes, your idea is possible. The ClassNotFoundException exception is thrown because you are trying to unparcel a class that was created in a different process by a different ClassLoader.

    ResultReceiver class implements Parcelable interface which is suitable for inter-process calls (IPC), however to read your object in the service you need to use the same ClassLoader, that was used for object creation in the client application (i.e. in the activity). To get that ClassLoader on the service side, call createPackageContext method passing client package name and CONTEXT_INCLUDE_CODE|CONTEXT_IGNORE_SECURITY combination of flags. This will return client Context object from which the correct ClassLoader object can be obtained.

    Example:

    public int onStartCommand(Intent intent, int flags, int startId) {
      try {
    
    // assuming SignerClient activity is located in the package "com.example.client.A"
        Context context = createPackageContext("com.example.client.A", Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
        ClassLoader cl = context.getClassLoader();
    
        Bundle bundle = intent.getExtras();
        bundle.setClassLoader(cl);
        ResultReceiver rr = bundle.getParcelable("resultreceiver");
    
    //... your interaction with ResultReceiver ...
        rr.send(1, null);   // will result in a onReceiveResult call in the client activity
    
      } catch (NameNotFoundException e) {
        Log.e("MyService", "SignerClient package context was not found", e);
        throw new RuntimeException(e);
      }
      return START_STICKY;
    }
    

    I’ve just used it in my code – works like a charm.

    UPDATE
    However I suggest to consider using Messenger instead of ResultReceiver. It implements Parcelable interface and does not need to be extended thus the ClassLoader issue isn’t possible. And it’s also recommended in the official documentation.

    UPDATE 2
    In case you still prefer to use ResultReceiver take a look at Robert’s answer in this thread. It looks cleaner and simpler than hacky context manipulations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: package com.powergroupbd.timer; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.CountDownTimer;
I have class A which extends the Activity class. This class is in package
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
I have activity A in package one, and I want to run an intent
I have created following activity package com.ali.test; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import
Ex: I have a project with UI contains a button.. Activity: package android.tuanshaker.myproject.com; import
I have created a Android Application with one Activity and package name com.explore <category
I have ordinary activity with Option Menu, which I created by this code: @Override
I have this activity, package org.dewsworld.ui; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; public class
I trying to make a project, I have one activity and one service from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.