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

  • Home
  • SEARCH
  • 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 1113111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:48:23+00:00 2026-05-17T02:48:23+00:00

public class XPBN extends Activity{ private Map _map; @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState);

  • 0
public class XPBN extends Activity{
private Map _map;

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    final Map data = (Map)getLastNonConfigurationInstance();
    if (data == null) {
        Toast.makeText(this, "New Map", Toast.LENGTH_SHORT).show();
        _map = new Map(this);
    } else {
        Toast.makeText(this, "Old Map", Toast.LENGTH_SHORT).show();
        _map = (Map)data;
    }

    setContentView(_map);
}

@Override
public Object onRetainNonConfigurationInstance() {
    Toast.makeText(this, "Saving Configuration...", Toast.LENGTH_LONG).show();
    return _map;
}
}

I am going to suppose that the title I gave this forum-thread states the problem I am experiencing pretty thoroughly. I have also edited the code to try to save a string object and then recover the string object through the getLastNonConfigurationInstance(), just to see to what extent I could get it to work for me, but it still seemed to return null. I have not tried calling it from onStart() or onRestart() or onResume(), but from what I have read, it is usually only called from onCreate(Bundle) anyways. This has got me really confused… :/

I figured it may be of some help to know a little about my Map class object, so here’s (some of) the code from it:

public class Map extends SurfaceView implements SurfaceHolder.Callback{
private MapThread _mapThread;
private int _terrain[][];
private ArrayList<Player> playerList;
private Bitmap _blueback;
private Bitmap _bluefront;
private Bitmap _blueleft;
private Bitmap _blueright;
private Bitmap _greenback;
private Bitmap _greenfront;
private Bitmap _greenleft;
private Bitmap _greenright;
private Bitmap _redfront;
private Bitmap _redback;
private Bitmap _redleft;
private Bitmap _redright;
private Bitmap _robot1;
private Bitmap _forest;
private Bitmap _grass;
private Bitmap _mountain;
private Bitmap _tree;
@SuppressWarnings("unused")
private boolean _mapLoaded = false;
private int _viewX = 0;
private int _viewY = 0;

Map(Context context){
    super(context);
    getHolder().addCallback(this);
    _mapThread = new MapThread(this);
    setFocusable(true);

    _terrain = new int[100][100];
    playerList = new ArrayList<Player>();
    addPlayer(0, 0, 0);

    _blueback = BitmapFactory.decodeResource(context.getResources(), R.drawable.blueback);
    _bluefront = BitmapFactory.decodeResource(context.getResources(), R.drawable.bluefront);
    _blueleft = BitmapFactory.decodeResource(context.getResources(), R.drawable.blueleft);
    _blueright = BitmapFactory.decodeResource(context.getResources(), R.drawable.blueright);
    _greenback = BitmapFactory.decodeResource(context.getResources(), R.drawable.greenback);
    _greenfront = BitmapFactory.decodeResource(context.getResources(), R.drawable.greenfront);
    _greenleft = BitmapFactory.decodeResource(context.getResources(), R.drawable.greenleft);
    _greenright = BitmapFactory.decodeResource(context.getResources(), R.drawable.greenright);
    _redback = BitmapFactory.decodeResource(context.getResources(), R.drawable.redback);
    _redfront = BitmapFactory.decodeResource(context.getResources(), R.drawable.redfront);
    _redleft = BitmapFactory.decodeResource(context.getResources(), R.drawable.redleft);
    _redright = BitmapFactory.decodeResource(context.getResources(), R.drawable.redright);
    _robot1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.robot1);
    _forest = BitmapFactory.decodeResource(context.getResources(), R.drawable.forest);
    _grass = BitmapFactory.decodeResource(context.getResources(), R.drawable.grass);
    _mountain = BitmapFactory.decodeResource(context.getResources(), R.drawable.mountain);
    _tree = BitmapFactory.decodeResource(context.getResources(), R.drawable.tree);

    TouchScreenHandler handler = new TouchScreenHandler(); // This includes 2 other nested-class threads
    this.setOnTouchListener(handler);
}

Perhaps there lies something in the complexity of the Object returned by onRetainNonConfigurationInstance() that might be contributing to my problems?

Or lastly is there something (like a Activity or Application property) in my Manifest.xml file that is the problem?

If any further information is required, please let me know, as I will be checking back on this post frequently until I can get past this little bump in the road.
PS: I have this problem with both ADB and my device.
PSS: most importantly, a big THANKS to this community for the help and support, as it is greatly appreciated! 😀

  • 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-17T02:48:24+00:00Added an answer on May 17, 2026 at 2:48 am

    Have you confirmed that onRetainNonConfigurationInstance() is actually being called? I see you have a toast being displayed in it, but you don’t actually say it is being shown. (And why a toast instead of just a Log.i()?)

    As the documentation says, “this function is called purely as an optimization, and you must not rely on it being called.” You can’t rely on this actually happening. The only time it will happen in fact is when a configuration change happens while your activity is in the foreground, in which case the framework will in one feel swoop call onRetainNonConfigurationInstance() and destroy the current instance and immediately create a new instance with the retained object available to it. There should be pretty much nothing you can do that would prevent the object you return from appearing in the new instance… though I guess if you call finish() or such on the old one, that might do it.

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

Sidebar

Related Questions

public class Greeter extends MovieClip { public function Greeter() { addEventListener(Event.ADDED_TO_STAGE, go); } private
public class MyClass { public int Age; public int ID; } public void MyMethod()
public class Test { public static void main(String[] args) { } } class Outer
public class doublePrecision { public static void main(String[] args) { double total = 0;
public class WrapperTest { static { print(10); } static void print(int x) { System.out.println(x);
public class WrapperTest { public static void main(String[] args) { Integer i = 100;
In the following snippet: public class a { public void otherMethod(){} public void doStuff(String
public class MyExample { public static void Main(String[] args) { string input = <a
public class Main3 { public static void main(String[] args) { Integer min = Integer.MIN_VALUE;
public class EventsType { public event EventHandler> NewEvent; public void SmthHappened(string data) { MyEventArgs<Object>

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.