Reputation: 81
I have 4 tabs. One Tab 1 (Respond) I want to start another activity say click on continue button and should go to another page (Respond1) where I have back button. Everything should be on Tab 1 itself. I am having problems like if I go 4 to 5 times I get stack over flow error.
Respond.Java
package com.muo.Livegroups;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.util.Log;
public class Respond extends ActivityGroup
{
protected static LocalActivityManager mLocalActivityManager;
public static final String LOG_TAG = "muo";
@Override
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.respond);
//Continue button on Respond page
Button next1 = (Button) findViewById(R.id.Continue);
next1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
Intent myIntent = new Intent(view.getContext(), Respond1.class);
startActivityForResult(myIntent, 0);
// StringBuffer urlString = new StringBuffer();
// myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// replaceContentView("Respond1",myIntent);
int mInt=0;
Log.v(LOG_TAG, "mInt Value: " + mInt);
}
});
}
public void replaceContentView(String id, Intent newIntent)
{
View view = getLocalActivityManager()
.startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY ))
.getDecorView();
this.setContentView(view);
}
}
Respond1.Java
package com.muo.Livegroups;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class Respond1 extends ActivityGroup
{
protected static LocalActivityManager mLocalActivityManager;
public static final String LOG_TAG = "muo1";
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.respond1);
Button next = (Button) findViewById(R.id.Button03);
next.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
Intent intent = new Intent();
setResult(RESULT_OK, intent);
finish();
// Intent myIntent = new Intent(view.getContext(), Respond.class);
// StringBuffer urlString = new StringBuffer();
// myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// replaceContentView("Respond",intent);
int mInt1=0;
Log.v(LOG_TAG, "mInt Value: " + mInt1);
}
});
}
public void replaceContentView(String id, Intent newIntent)
{
View view = getLocalActivityManager()
.startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP ))
.getDecorView();
this.setContentView(view);
}
}
Upvotes: 0
Views: 538
Reputation: 564
main activitity should be ActivityGroup and put this code where you start new activity
Intent intent = new Intent(v.getContext(), Activity1.class);
Activity1 parentActivity = (Activity1)getParent();
parentActivity.replaceContentView("activity1", intent,
Intent.FLAG_ACTIVITY_REORDER_TO_FRONT );
Upvotes: 0
Reputation: 30825
You should consider making the two activities fragments and putting them together in one activity in the tab. If you're using an api level less than 3.0, please look at the android compatibility package.
Upvotes: 1