单个选项卡中有 2 个活动

发布于 2024-12-11 02:32:33 字数 3380 浏览 1 评论 0原文

我有 4 个标签。一个选项卡 1(响应)我想开始另一项活动,例如单击“继续”按钮,并且应该转到另一个页面(响应 1),其中有后退按钮。一切都应该在选项卡 1 本身上。我遇到的问题是,如果我运行 4 到 5 次,就会出现堆栈溢出错误。

响应.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);
    }
}

响应1.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);
    }
}

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);
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦÷微暖 2024-12-18 02:32:33

您应该考虑将这两个活动片段并将它们放在一个活动中在选项卡中。如果您使用的 api 级别低于 3.0,请查看 android 兼容性包。

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.

我很坚强 2024-12-18 02:32:33

主要活动应该是 ActivityGroup 并将此代码放在开始新活动的位置

  Intent intent = new Intent(v.getContext(), Activity1.class);
Activity1 parentActivity = (Activity1)getParent();  
parentActivity.replaceContentView("activity1", intent, 
             Intent.FLAG_ACTIVITY_REORDER_TO_FRONT ); 

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 ); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文