从不同的意图中获得额外收益

我有一个MainActivity,它具有打开同一PopUpActivty的不同按钮。 我从方法中的每个按钮发送带有意图附加的标签。此Extra应该可以帮助我知道在MainActivity中单击了哪个按钮。我想用PopupWindow差异Avtivities中的一个按钮打开此信息,这取决于在MainActvity上单击了哪个按钮。

我的问题:

我在PopUpWindow中使用getIntent来获取Extra,但是问题是,我从每个按钮中获取所有标签,而不仅仅是单击按钮。

 public void startPopUpActivity (View view) {

        String tag = view.getTag().toString();

        Intent startKarteikartenActivity = new Intent (this, popUpWindow.class );
        startKarteikartenActivity.putExtra("Activity", tag);
        startActivity(startKarteikartenActivity);
    }

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






public class popUpWindow extends Activity {

    public void startActicity (View view) {
        Intent getIntent = getIntent();

        String activity = getIntent.getStringExtra("Activity");

        switch  (activity){

            case "1":
                Intent intentKarteikarte = new Intent(getApplicationContext(), Karteikarten.class);
                startActivity(intentKarteikarte);
            case "2":
                Intent intentAusbildungsmethoden = new Intent(getApplicationContext(), Ausbildungsmethoden.class);
                startActivity(intentAusbildungsmethoden);
            case "3":
                Intent intentFallbearbeitung = new Intent(getApplicationContext(), Fallbearbeitung.class);
                startActivity(intentFallbearbeitung);
            case "4":
                Intent intentBonus = new Intent(getApplicationContext(), Bonus.class);
                startActivity(intentBonus);
            case "5":
                Intent intentGeneralprobe = new Intent(getApplicationContext(), Generalprobe.class);
                startActivity(intentGeneralprobe);

        }

    }

    public void openPremiumversion (View view) {

        Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
        startActivity(browserIntent);

    }

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

        DisplayMetrics displayMetrics = new DisplayMetrics();

        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

        int width = displayMetrics.widthPixels;
        int height = displayMetrics.heightPixels;

        getWindow().setLayout((int) (width * 0.8), (int) (height * 0.5));
    }
}`
评论
mneque
mneque

Your method startActvity you forgot add break in switch

      switch  (activity){

            case "1":
                Intent intentKarteikarte = new Intent(getApplicationContext(), Karteikarten.class);
                startActivity(intentKarteikarte);
                break;
            case "2":
                Intent intentAusbildungsmethoden = new Intent(getApplicationContext(), Ausbildungsmethoden.class);
                startActivity(intentAusbildungsmethoden);
                break;
            case "3":
                Intent intentFallbearbeitung = new Intent(getApplicationContext(), Fallbearbeitung.class);
                startActivity(intentFallbearbeitung);
                break;
            case "4":
                Intent intentBonus = new Intent(getApplicationContext(), Bonus.class);
                startActivity(intentBonus);
                break;
            case "5":
                Intent intentGeneralprobe = new Intent(getApplicationContext(), Generalprobe.class);
                startActivity(intentGeneralprobe);
                break;
        }
点赞
评论