tru7
tru7

Reputation: 7222

Activity as a intent receiver to just start another and quit

My app can be called from different intents, specifically from Android TV. I have created a special activity for this with the proper intent filter in the manifest. (If that intent (TV) were starting the main activity gave problems, with a specific activity works well)

My question is, that TVActivity just starts the main activity in onCreate() and should stop as it has no further use. Calling finish in onCreate() or onStart() seems a bad idea. What would be a clean and safe way to kill this activity and leave the other running?

Upvotes: 0

Views: 58

Answers (1)

Nik Myers
Nik Myers

Reputation: 1873

I'm not sure that i got your question right, but you can see common usage of SplashActivity :

/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {       
        super.onCreate(icicle);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splash_screen);

        /* New Handler to start the Menu-Activity 
         * and close this Splash-Screen after some seconds.*/
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                WeekplanHepler.isLoggedIn(SplashActivity.this);
                Intent mainIntent = new Intent(SplashActivity.this, YourActivity.class);
                SplashActivity.this.finish();
                SplashActivity.this.startActivity(mainIntent);
            }
        }, SPLASH_DISPLAY_LENGTH);
    }

As you see, it's finished just before starting another because we no longer need it, so, if you have similar situation, it's ok to do finish whenever new activity starts

Upvotes: 1

Related Questions