Question

The app I'm making will end with opening the SMS inbox for the user convenience and is at this stage finished. Normally then the back key would go back to the activity but since this is does not make any sense for the user I simply tried to finish the app. This worked perfectly and I even release a version at this stage... however... the home key, who could guess that it is a quite popular thing to press when you don't want that annoying feeling of going backwards in life. And now it got messy... basically if the user press home from the inbox the app i lost in some rather strange way that I don't know if I should call a bug or a security feature. The next time I start the app it will go directly to the new intent (showing the inbox) bypassing my app completely, no onResume or anything. Very bad since my app is overridden and becomes a open the inbox link.

Is there any way to make this work at all?

import android.os.Bundle;
import android.view.View;
import android.app.Activity;
import android.content.Intent;

public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
    }

    public void onButtonClick(View v) {
        finish();

        final Intent smsIntent = new Intent(Intent.ACTION_MAIN);
        smsIntent.addCategory(Intent.CATEGORY_DEFAULT);
        smsIntent.setType("vnd.android-dir/mms-sms");
        startActivity(smsIntent);       
    }
}
Was it helpful?

Solution

Depending on what you want there are a few things you can try

  • add to your root activity in the manifest android:clearTaskOnLaunch="true"
    With this flag your app will start from the root activity whenever relaunch from home.
  • add smsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    This will clear the SMS inbox activity and all activities above it in the task stack when relaunch the app from home.
  • add `smsIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); This will clear the SMS inbox activity when relaunch.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top