0

I have 2 simple activities (relative layouts hosting 1 button each) under one tab. Each of them has a link to each other so you can go from one activity to another (everything works under the same tab). The program crashes after the 3rd loop (1st activity - 2nd - 1st - 2nd - 1st - 2nd).

I go from one activity to another with the following code:

Tabs s = (Tabs) getParent();
Intent myIntent = new Intent(getApplicationContext(), Map.class);
View view = s.getLocalActivityManager().startActivity("map",
    myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
setContentView(view);

It doesn't matter what layouts I have in the activities, basically it still crashes every 3rd loop.

I have no other ideas except that android interprets this navigation (from 1 activity to another under the same tab) as an infinitive loop? Which basically users does, not a loop that is being programmed by me.

Is it some android bug or I am doing something wrong?

I am getting this error:

02-17 10:36:00.566: E/AndroidRuntime(4155): FATAL EXCEPTION: main
02-17 10:36:00.566: E/AndroidRuntime(4155): java.lang.StackOverflowError
02-17 10:36:00.566: E/AndroidRuntime(4155):     at android.widget.TextView.getExtendedPaddingTop(TextView.java:1281)
02-17 10:36:00.566: E/AndroidRuntime(4155):     at android.widget.TextView.getVerticalOffset(TextView.java:3570)
02-17 10:36:00.566: E/AndroidRuntime(4155):     at android.widget.TextView.onDraw(TextView.java:4050)
02-17 10:36:00.566: E/AndroidRuntime(4155):     at android.view.View.draw(View.java:6880)
02-17 10:36:00.566: E/AndroidRuntime(4155):     at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
02-17 10:36:00.566: E/AndroidRuntime(4155):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-17 10:36:00.566: E/AndroidRuntime(4155):     at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
02-17 10:36:00.566: E/AndroidRuntime(4155):     at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
02-17 10:36:00.566: E/AndroidRuntime(4155):     at android.view.View.draw(View.java:6883)

EDIT: OK, I have an idea why this error appears. Every time I go from one activity to another I'm creating new Intent and starting new Activity. That might be the case. But how can I reuse them? If I try to reuse the view I get this error:

02-17 13:14:03.429: E/AndroidRuntime(5374): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Mindaugas Svirskas
  • 1,039
  • 1
  • 9
  • 13

1 Answers1

0

The first suspicious thing is the use of getApplicationContext(). Using getApplicationContext() "is almost always wrong", as explained here: When to call activity context OR application context?

Community
  • 1
  • 1