0

我的情况如下:

             __> B(SETUP PAGE)------------> D(ACCOUNT SETTINGS) *all users have  
            /         |                                          same layout
           /     (has 10 rows/users) 
          /      (Click only 1 of the account/row, the it is highlight)
         /       (once the row is selected, and click done, the data saved in D
        /         will be jumped and passed to C.        
A(WELCOME PAGE)
        \
         \__> C(REMOTE PAGE)

以上是我整体方案的图解~

我不知道如何将数据从D通过B传递到C〜有人可以指导我吗?C 中的代码是不完整的,因为它有其他与它无关的函数和类。

代码:

// Code for B:

public class AccountSetup extends Activity {

    TableRow tableRow1, tableRow2, tableRow3, tableRow4, tableRow5, tableRow6, tableRow7, tableRow8, tableRow9, tableRow10;
    View border1, border2, border3, border4, border5, border6, border7, border8, border9, border10;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.account_main);
        this.initViews();

        Button btnAdd = (Button)findViewById(R.id.btnAdd);        
        btnAdd.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (tableRow1.getVisibility() == (View.GONE)){
                    tableRow1.setVisibility(View.VISIBLE);
                    border1.setVisibility(View.VISIBLE);}
                else if (tableRow2.getVisibility() == (View.GONE)){
                        tableRow2.setVisibility(View.VISIBLE);
                        border2.setVisibility(View.VISIBLE);}
                else if (tableRow3.getVisibility() == (View.GONE)){
                        tableRow3.setVisibility(View.VISIBLE);
                        border3.setVisibility(View.VISIBLE);}
                else if (tableRow4.getVisibility() == (View.GONE)){
                        tableRow4.setVisibility(View.VISIBLE);
                        border4.setVisibility(View.VISIBLE);}
                else if (tableRow5.getVisibility() == (View.GONE)){
                        tableRow5.setVisibility(View.VISIBLE);
                        border5.setVisibility(View.VISIBLE);}
                else if (tableRow6.getVisibility() == (View.GONE)){
                        tableRow6.setVisibility(View.VISIBLE);
                        border6.setVisibility(View.VISIBLE);}
                else if (tableRow7.getVisibility() == (View.GONE)){
                        tableRow7.setVisibility(View.VISIBLE);
                        border7.setVisibility(View.VISIBLE);}
                else if (tableRow8.getVisibility() == (View.GONE)){
                        tableRow8.setVisibility(View.VISIBLE);
                        border8.setVisibility(View.VISIBLE);}
                else if (tableRow9.getVisibility() == (View.GONE)){
                        tableRow9.setVisibility(View.VISIBLE);
                        border9.setVisibility(View.VISIBLE);}
                else if (tableRow10.getVisibility() == (View.GONE)){
                        tableRow10.setVisibility(View.VISIBLE);
                        border10.setVisibility(View.VISIBLE);}
                else{
                    final AlertDialog alertDialog = new AlertDialog.Builder(AccountSetup.this).create();
                    alertDialog.setTitle("Alert Message");
                    alertDialog.setMessage("You have reached the maximum number of users");
                    alertDialog.setIcon(R.drawable.icon_tick);
                    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        //Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
                        }
                    });
                    alertDialog.show();
                }
              }});
    }

    private void initViews(){ 
        //Account 1  
        tableRow1  = (TableRow)findViewById(R.id.tableRow1);
        border1  = (View)findViewById(R.id.border1);
        tableRow1.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            tableRow1.setVisibility(View.GONE);
            border1.setVisibility(View.GONE);
            return true;
            }
        });
        tableRow1.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                tableRow1.setEnabled(true);
                tableRow1.setSelected(true);
                }
        });
        Button iconNext1  = (Button)findViewById(R.id.iconNext1);  
        iconNext1.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent Intent1 = new Intent(AccountSetup.this, AccountSettingActivity1.class);
            Intent1.putExtra("rowid","1"); 
            startActivityForResult(Intent1, 100);
            }
        });

        //Account 2
        tableRow2  = (TableRow)findViewById(R.id.tableRow2);  
        border2  = (View)findViewById(R.id.border2);
        tableRow2.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            tableRow2.setVisibility(View.GONE);
            border2.setVisibility(View.GONE);
            return true;
            }
        });
        tableRow2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                tableRow2.setEnabled(true);
                }
        });
        Button iconNext2  = (Button)findViewById(R.id.iconNext2);       
        iconNext2.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent Intent2 = new Intent(AccountSetup.this, AccountSettingActivity2.class);
            Intent2.putExtra("rowid","2"); 
            startActivityForResult(Intent2, 200);
            }
        });

        //Account 3
        tableRow3  = (TableRow)findViewById(R.id.tableRow3);  
        border3  = (View)findViewById(R.id.border3);
        tableRow3.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            tableRow3.setVisibility(View.GONE);
            border3.setVisibility(View.GONE);
            return true;
            }
        });
        Button iconNext3  = (Button)findViewById(R.id.iconNext3);       
        iconNext3.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent Intent3 = new Intent(AccountSetup.this, AccountSettingActivity3.class);
            Intent3.putExtra("rowid","3"); 
            startActivityForResult(Intent3, 300);
            }
        });

        //Account 4
        tableRow4  = (TableRow)findViewById(R.id.tableRow4);  
        border4  = (View)findViewById(R.id.border4);
        tableRow4.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            tableRow4.setVisibility(View.GONE);
            border4.setVisibility(View.GONE);
            return true;
            }
        });
        Button iconNext4  = (Button)findViewById(R.id.iconNext4);       
        iconNext4.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent Intent4 = new Intent(AccountSetup.this, AccountSettingActivity4.class);
            Intent4.putExtra("rowid","4"); 
            startActivityForResult(Intent4, 400);
            }
        });

        //Account 5
        tableRow5  = (TableRow)findViewById(R.id.tableRow5);  
        border5  = (View)findViewById(R.id.border5);
        tableRow5.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            tableRow5.setVisibility(View.GONE);
            border5.setVisibility(View.GONE);
            return true;
            }
        });
        Button iconNext5  = (Button)findViewById(R.id.iconNext5);       
        iconNext5.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent Intent5 = new Intent(AccountSetup.this, AccountSettingActivity5.class);
            Intent5.putExtra("rowid","5"); 
            startActivityForResult(Intent5, 500);
            }
        });

        //Account 6
        tableRow6  = (TableRow)findViewById(R.id.tableRow6);  
        border6  = (View)findViewById(R.id.border6); 
        tableRow6.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            tableRow6.setVisibility(View.GONE);
            border6.setVisibility(View.GONE);
            return true;
            }
        });
        Button iconNext6  = (Button)findViewById(R.id.iconNext6);       
        iconNext6.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent Intent6 = new Intent(AccountSetup.this, AccountSettingActivity6.class);
            Intent6.putExtra("rowid","6"); 
            startActivityForResult(Intent6, 600);
            }
        });

        //Account 7
        tableRow7  = (TableRow)findViewById(R.id.tableRow7);  
        border7  = (View)findViewById(R.id.border7); 
        tableRow7.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            tableRow7.setVisibility(View.GONE);
            border7.setVisibility(View.GONE);
            return true;
            }
        });
        Button iconNext7  = (Button)findViewById(R.id.iconNext7);       
        iconNext7.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent Intent7 = new Intent(AccountSetup.this, AccountSettingActivity7.class);
            Intent7.putExtra("rowid","7"); 
            startActivityForResult(Intent7, 700);
            }
        });

        //Account 8
        tableRow8  = (TableRow)findViewById(R.id.tableRow8);  
        border8  = (View)findViewById(R.id.border8);  
        tableRow8.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            tableRow8.setVisibility(View.GONE);
            border8.setVisibility(View.GONE);
            return true;
            }
        });
        Button iconNext8  = (Button)findViewById(R.id.iconNext8);       
        iconNext8.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent Intent8 = new Intent(AccountSetup.this, AccountSettingActivity8.class);
            Intent8.putExtra("rowid","8"); 
            startActivityForResult(Intent8, 800);
            }
        });

        //Account 9
        tableRow9  = (TableRow)findViewById(R.id.tableRow9);  
        border9  = (View)findViewById(R.id.border9);  
        tableRow9.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            tableRow9.setVisibility(View.GONE);
            border9.setVisibility(View.GONE);
            return true;
            }
        });
        Button iconNext9  = (Button)findViewById(R.id.iconNext9);       
        iconNext9.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent Intent9 = new Intent(AccountSetup.this, AccountSettingActivity9.class);
            Intent9.putExtra("rowid","9"); 
            startActivityForResult(Intent9, 900);
            }
        });

        //Account 10
        tableRow10  = (TableRow)findViewById(R.id.tableRow10);  
        border10  = (View)findViewById(R.id.border10);  
        tableRow10.setOnLongClickListener(new OnLongClickListener() {
        public boolean onLongClick(View v) {
            tableRow10.setVisibility(View.GONE);
            border10.setVisibility(View.GONE);
            return true;
            }
        });
        Button iconNext10  = (Button)findViewById(R.id.iconNext10);       
        iconNext10.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent Intent10 = new Intent(AccountSetup.this, AccountSettingActivity10.class);
            Intent10.putExtra("rowid","10"); 
            startActivityForResult(Intent10, 1000);
            }
        });
    }

    public void onBackPressed() {
        Intent i = new Intent(AccountSetup.this, WelcomeActivity.class);
        startActivity(i);
        finish();
        super.onBackPressed();
    }

    @Override
    protected void onActivityResult(int requestCode,int resultCode, Intent data) {
    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
       if (requestCode == 100) {
           if (resultCode == RESULT_OK) {      
               data.getStringExtra("accountName1");   
               TextView user1 = (TextView)findViewById(R.id.user1);  
               user1.setText(sp.getString("accountName1", ""));
           }
       }
       else if (requestCode == 200) {
           if (resultCode == RESULT_OK) {      
               data.getStringExtra("accountName2");   
               TextView user2 = (TextView)findViewById(R.id.user2);  
               user2.setText(sp.getString("accountName2", ""));
           }
       }
       else if (requestCode == 300) {
           if (resultCode == RESULT_OK) {      
               data.getStringExtra("accountName3");   
               TextView user3 = (TextView)findViewById(R.id.user3);  
               user3.setText(sp.getString("accountName3", ""));
           }
       }
       else if (requestCode == 400) {
           if (resultCode == RESULT_OK) {      
               data.getStringExtra("accountName4");   
               TextView user4 = (TextView)findViewById(R.id.user4);  
               user4.setText(sp.getString("accountName4", ""));
           }
       }
       else if (requestCode == 500) {
           if (resultCode == RESULT_OK) {      
               data.getStringExtra("accountName5");   
               TextView user5  = (TextView)findViewById(R.id.user5);  
               user5.setText(sp.getString("accountName5", ""));
           }
       }
       else if (requestCode == 600) {
           if (resultCode == RESULT_OK) {      
               data.getStringExtra("accountName6");   
               TextView user6 = (TextView)findViewById(R.id.user6);  
               user6.setText(sp.getString("accountName6", ""));
           }
       }
       else if (requestCode == 700) {
           if (resultCode == RESULT_OK) {      
               data.getStringExtra("accountName7");   
               TextView user7 = (TextView)findViewById(R.id.user7);  
               user7.setText(sp.getString("accountName7", ""));
           }
       }
       else if (requestCode == 800) {
           if (resultCode == RESULT_OK) {      
               data.getStringExtra("accountName8");   
               TextView user8 = (TextView)findViewById(R.id.user8);  
               user8.setText(sp.getString("accountName8", ""));
           }
       }
       else if (requestCode == 900) {
           if (resultCode == RESULT_OK) {      
               data.getStringExtra("accountName9");   
               TextView user9 = (TextView)findViewById(R.id.user9);  
               user9.setText(sp.getString("accountName9", ""));
           }
       }
       else if (requestCode == 1000) {
           if (resultCode == RESULT_OK) {      
               data.getStringExtra("accountName10");   
               TextView user10 = (TextView)findViewById(R.id.user10);  
               user10.setText(sp.getString("accountName10", ""));
           }
       }
    }

    @Override
    public void onResume() {
        super.onResume();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        TextView user1  = (TextView)findViewById(R.id.user1);
        user1.setText(sp.getString("accountName1", ""));
        TextView user2  = (TextView)findViewById(R.id.user2);
        user2.setText(sp.getString("accountName2", ""));
        TextView user3  = (TextView)findViewById(R.id.user3);
        user3.setText(sp.getString("accountName3", ""));
        TextView user4  = (TextView)findViewById(R.id.user4);
        user4.setText(sp.getString("accountName4", ""));
        TextView user5  = (TextView)findViewById(R.id.user5);
        user5.setText(sp.getString("accountName5", ""));
        TextView user6  = (TextView)findViewById(R.id.user6);
        user6.setText(sp.getString("accountName6", ""));
        TextView user7  = (TextView)findViewById(R.id.user7);
        user7.setText(sp.getString("accountName7", ""));
        TextView user8  = (TextView)findViewById(R.id.user8);
        user8.setText(sp.getString("accountName8", ""));
        TextView user9  = (TextView)findViewById(R.id.user9);
        user9.setText(sp.getString("accountName9", ""));
        TextView user10 = (TextView)findViewById(R.id.user10);
        user10.setText(sp.getString("accountName10", ""));
    }
}

// Code D:  ----------------------------------------------------------

public class AccountSettingActivity1 extends Activity{

    private EditText etAccountName;
    private EditText etWanIp;
    private EditText etLocalIp;
    private EditText etPort;
    private EditText etPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.account_tab_content_setting);
        this.initViews();

    }
        private void initViews(){
            etAccountName = (EditText)this.findViewById(R.id.etAccountName);
            etWanIp = (EditText)this.findViewById(R.id.etWanIp);
            etLocalIp = (EditText)this.findViewById(R.id.etLocalIp);
            etPort = (EditText)this.findViewById(R.id.etPort);
            etPassword = (EditText)this.findViewById(R.id.etPassword);

            // Assigns value
            SharedPreferences  sp = PreferenceManager.getDefaultSharedPreferences(this);
            etAccountName.setText(sp.getString("accountName1", ""));
            etWanIp.setText(sp.getString("wanIp1", ""));
            etLocalIp.setText(sp.getString("localIp1", ""));
            etPort.setText(sp.getString("port1", ""));
            etPassword.setText(sp.getString("password1", ""));

            etWanIp.setOnFocusChangeListener(new OnFocusChangeListener(){
                @Override
                public void onFocusChange(View arg0, boolean hasFocus) {
                    if(!hasFocus){
                        System.out.println("lost focus");
                        AccountSettingActivity1.this.saveSettings();
                    }
                }
            });
        }

        private void saveSettings(){
            String accountName1 = etAccountName.getText().toString();
            String wanIp1 = etWanIp.getText().toString();
            String localIp1 = etLocalIp.getText().toString();
            String port1 = etPort.getText().toString();
            String password1 = etPassword.getText().toString();

            accountName1 = (accountName1.trim().length() == 0)? "User": accountName1;
            wanIp1 = (wanIp1.trim().length() == 0)? "0.0.0.0": wanIp1;
            localIp1 = (localIp1.trim().length() == 0)? "0.0.0.0": localIp1;
            port1 = (port1.trim().length() == 0)? "8000": port1;
            password1 = (password1.trim().length() == 0)? "xxxx": password1;

            etAccountName.setText(accountName1);
            etWanIp.setText(wanIp1);
            etLocalIp.setText(localIp1);
            etPort.setText(port1);
            etPassword.setText(password1);

            SharedPreferences.Editor editor = PreferenceManager
                    .getDefaultSharedPreferences(this).edit();
            editor.putString("accountName1", etAccountName.getText().toString());
            editor.putString("wanIp1", etWanIp.getText().toString());
            editor.putString("localIp1", etLocalIp.getText().toString());
            editor.putString("port1", etPort.getText().toString());
            editor.putString("password1", etPassword.getText().toString());
            editor.commit();
        }

    public void onBackPressed() {
        saveSettings();
        etAccountName = (EditText)findViewById(R.id.etAccountName);
        etWanIp = (EditText)findViewById(R.id.etWanIp);
        etLocalIp = (EditText)findViewById(R.id.etLocalIp);
        etPort = (EditText)findViewById(R.id.etPort);
        etPassword = (EditText)findViewById(R.id.etPassword);
        String accountName = etAccountName.getText().toString();
        String wanIp = etWanIp.getText().toString();
        String localIp = etLocalIp.getText().toString();
        String port = etPort.getText().toString();
        String password = etPassword.getText().toString();

        Intent i = new Intent(AccountSettingActivity1.this, AccountSetup.class);
        i.putExtra("accountName1" ,accountName);
        i.putExtra("wanIp1" ,wanIp);
        i.putExtra("localIp1" ,localIp);
        i.putExtra("port1" ,port);
        i.putExtra("password1" ,password);
        setResult(RESULT_OK,  i);     
        finish();
        super.onBackPressed();
    }   

    @Override
    protected void onPause() {
        // When user leaves this tab, saves the values
        this.saveSettings();
        super.onPause();
    }
}

// Code C: --------------------------------------------------------------

public class SettingActivity extends Activity implements ToolbarCallback {

    private ToolBar toolbar;
    private EditText etAccountName;
    private EditText etWanIp;
    private EditText etLocalIp;
    private EditText etPort;
    private EditText etPassword;
    private Button btnConnection;
    private ViewSwitcher switcher;
    private RelativeLayout infoView;
    private BluGuardProto2Activity mainActivity;
    private BluGuardProtocol bluguard;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.tab_content_setting);
        this.initViews();

        bluguard = BluGuardProtocol.getInstance();
    }

    @Override
    protected void onResume() {
        super.onResume();
        this.toolbar.setProtocolCallback(this);
        this.toolbar.setRightButtonDrawable(R.drawable.ic_btn_info);
        this.toolbar.setRightButtonOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0) {
                showInfoView();
            }
        });

        this.toolbar.setLeftButtonOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0) {
                saveSettings();

                if(bluguard.isLoggedInAndConnected()){
                    toolbar.disconnect();
                } else {
                    toolbar.connect();
                }
            }
        });

        if(bluguard.isLoggedInAndConnected()){
            btnConnection.setText(getResources().getString(R.string.disconnect));
        } else {
            btnConnection.setText(getResources().getString(R.string.connect));
        }
    }

    private void initViews(){
        mainActivity = (BluGuardProto2Activity) this.getParent();
        toolbar = (ToolBar)mainActivity.findViewById(R.id.toolbar);
        etAccountName = (EditText)this.findViewById(R.id.etAccountName);
        etWanIp = (EditText)this.findViewById(R.id.etWanIp);
        etLocalIp = (EditText)this.findViewById(R.id.etLocalIp);
        etPort = (EditText)this.findViewById(R.id.etPort);
        etPassword = (EditText)this.findViewById(R.id.etPassword);
        switcher = (ViewSwitcher)this.findViewById(R.id.switcher);
        infoView = (RelativeLayout)this.findViewById(R.id.infoView);
        btnConnection = (Button)this.findViewById(R.id.btnConnection);

        btnConnection.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0) {
                if(bluguard.isLoggedInAndConnected()){
                    toolbar.disconnect();
                    btnConnection.setText(getResources().getString(R.string.connect));
                } else {
                    saveSettings();
                    toolbar.connect();
                }
            }
        });

        // Asigns value
        SharedPreferences  sp = PreferenceManager.getDefaultSharedPreferences(this);
        etAccountName.setText(sp.getString("accountName", ""));
        etWanIp.setText(sp.getString("wanIp", ""));
        etLocalIp.setText(sp.getString("localIp", ""));
        etPort.setText(sp.getString("port", ""));
        etPassword.setText(sp.getString("password", ""));

        etWanIp.setOnFocusChangeListener(new OnFocusChangeListener(){
            @Override
            public void onFocusChange(View arg0, boolean hasFocus) {
                if(!hasFocus){
                    System.out.println("lost focus");
                    SettingActivity.this.saveSettings();
                }
            }
        });
    }

    private void showInfoView(){
        mainActivity.hideTabs();

        this.toolbar.setRightButtonDrawable(0);
        this.toolbar.setRightButtonOnClickListener(null);
        this.toolbar.setLeftButtonDrawable(R.drawable.ic_btn_back);
        this.toolbar.setLeftButtonOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                showSettingsView();
            }
        });
        this.toolbar.setText(getResources().getString(R.string.about));

        switcher.showNext();
    }

    private void showSettingsView(){
        this.toolbar.initConnectionUI();
        this.toolbar.setRightButtonDrawable(R.drawable.ic_btn_info);
        this.toolbar.setRightButtonOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View arg0) {
                showInfoView();
            }
        });
        mainActivity.showTabs();
        switcher.showPrevious();
    }

    @Override
    protected void onPause() {
        // When user leaves this tab, saves the values
        super.onPause();
    }

    @Override
    public void onBackPressed() {
        Intent i = new Intent(SettingActivity.this, WelcomeActivity.class);
        startActivity(i);
        finish();
        super.onBackPressed();
    }
}

// Code A: --------------------------------------------------------------
public class WelcomeActivity extends Activity {
    private Boolean firstRun;
    private long lastBackPressTime;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.welcome);

        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        if(sp.getBoolean("firstRun", true)){
            PreferenceManager.setDefaultValues(this, R.xml.preferences, true);
            firstRun = true;
            SharedPreferences.Editor editor = sp.edit();
            editor.putBoolean("firstRun", false);
            editor.commit();
        } else {
            firstRun = false;
        }

        this.initViews();
    }

    private void initViews(){
        Button btnContinue = (Button)this.findViewById(R.id.btnContinue);
        btnContinue.setOnClickListener(new OnClickListener(){
        //@Override
            public void onClick(View v) {
                Intent i = new Intent(WelcomeActivity.this, BluGuardProto2Activity.class);
//              i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                i.putExtra("firstRun", firstRun);
                startActivity(i);
            }
        });

        Button btnAccount = (Button)findViewById(R.id.btnAccount);        
        btnAccount.setOnClickListener(new OnClickListener() {
        //@Override
            public void onClick(View v) {
                Intent h = new Intent(WelcomeActivity.this,AccountSetup.class);
                startActivity(h);
              }});
    }

    @Override
    public void onBackPressed() {
        if (this.lastBackPressTime < System.currentTimeMillis() - 5000) {
            Toast.makeText(this, "Press back again to close this app",5000).show();
            this.lastBackPressTime = System.currentTimeMillis();
        } else {
            super.onBackPressed();
        }
    }
}
4

2 回答 2

1

从活动

检查此代码

 Intent productsIntent = new Intent(this, ProductActivity.class);
            Bundle param = new Bundle();
            param.putInt("Categories", 0); //Your id
            param.putCharSequence("CategoryName", "No Category");
            productsIntent.putExtras(param);

目标活动

 Bundle b = getIntent().getExtras();

 int id = b.getInt("Categories");
于 2013-05-13T08:28:42.473 回答
0

在乙

public void onBackPressed() {
    Intent i = new Intent(AccountSetup.this, WelcomeActivity.class);
    i.putExtra(what ever you need to send back to A);
    // more putExtra
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivity(i);
    super.onBackPressed();
}  

在一个

Button btnContinue = (Button)this.findViewById(R.id.btnContinue);
        btnContinue.setOnClickListener(new OnClickListener(){
        //@Override
            public void onClick(View v) {

                Intent i = new Intent(WelcomeActivity.this, BluGuardProto2Activity.class);
                Intent intent = getIntent();
                if (intent != null) {
                // get info send back from B make sure the info is not null
                // for example
                 String a = intent.getString("some key send back from B");
                i.putExtra("some key", a);
                } 
//              i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                i.putExtra("firstRun", firstRun);
                startActivity(i);
            }
        });

如果 A 在堆栈上,则调用 onNewIntent 而不是 onCreate 因此在 A 中添加此代码

@Override
protected void onNewIntent(Intent intent)
{
    super.onNewIntent(intent);

    setIntent(intent);
}
于 2013-05-13T08:53:08.397 回答