简体   繁体   中英

How to have multiple intents on the same java program

public class FullscreenActivity extends AppCompatActivity {
    private ImageButton act;
    private ImageButton sat;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fullscreen);
        act = (ImageButton) findViewById(R.id.act);
        sat = (ImageButton) findViewById(R.id.sat);
       sat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View v) {
                Intent intent = new Intent(FullscreenActivity.this, sat.class);
                startActivity(intent);
        act.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View v) {
                Intent intent = new Intent(FullscreenActivity.this, act.class);
                startActivity(intent);
            }

        });
    }}

What am I doing worng. I have a main UI with six imagebuttons, each one linking to a different activity. How can I link then all in the main activity which is called fullscreen activity

I think you want to bring the FullScreenActivity to front so you only have to finish the front Activity because you didn't finish it

just do finish(); on your sat.class or act.class

or....

You can do this too on your sat.class or act.class:

Intent i = new Intent(this, FullScreenActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(i);
    act.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick (View v) {
            Intent intent = new Intent(FullscreenActivity.this, act.class);
            startActivity(intent);
        }

    });

why is the above part inside some other button's click listener? Move it outside the anonymous inner method like

 sat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick (View v) {
                Intent intent = new Intent(FullscreenActivity.this, sat.class);
                startActivity(intent);
            }

});



act.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick (View v) {
                    Intent intent = new Intent(FullscreenActivity.this, act.class);
                    startActivity(intent);
                }

            });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM