0

What I want to do is pretty simple. I want app to launch sms app with pre-writen recipient. I made a new Android Application Project and used this code to lauch sms app. It works perfectly until I hit back button. It closes the sms app and then shows a blank screen enter image description here.

My code looks like:

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

    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    smsIntent.setType("vnd.android-dir/mms-sms");
    smsIntent.putExtra("address", "0123456789");
    startActivity(smsIntent);
}

I thought it has something to do with a layout and it starts a blank activity (?) at the start of the app so i tried to comment out the setting of a layout //setContentView(R.layout.activity_main);. It didn't help.

I also tried to override onBackPressed() which also didn't help.

@Override
public void onBackPressed()
{
    finish();
    System.exit(0);
}

Is it possible to disable showing of the blank screen ?

Community
  • 1
  • 1
nmck
  • 160
  • 1
  • 10
  • do you want to show the blank screen or not ? if yes then what exactly you want to have on this screen ? – Umair Sep 15 '14 at 10:49
  • Do you know that `System.exit(0);` is probably the worst thing you can do to your app? It will screw everything up and I mean EVERYTHING. Android doesn't work like a normal java application. You as a developer do not control the the lifecycle of anything. Just call `finish();` and the OS will take care of the rest. This `System.exit(0);` call may just be the cause of your problems in the first place. – Xaver Kapeller Sep 15 '14 at 10:49
  • @Darkie I don't want to show that blank screen at all. – nmck Sep 15 '14 at 10:58
  • @XaverKapeller Ye I read about that, but I was just trying things in hope to solve my problem, so I also tried that. – nmck Sep 15 '14 at 10:59
  • have you checked my answer @Broxe – Maveňツ Sep 15 '14 at 11:02
  • 1
    @Broxe just add finish(); like the answer below and I think you got it right now cheers :) – Umair Sep 15 '14 at 11:08
  • @maven Yes and I also tried it out, but Burak's solution seems a bit easier. Anyway thanks for your help :) – nmck Sep 15 '14 at 11:10

2 Answers2

2

Try this

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

    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    smsIntent.setType("vnd.android-dir/mms-sms");
    smsIntent.putExtra("address", "0123456789");
    startActivity(smsIntent);
    finish();
}
Maveňツ
  • 1
  • 12
  • 50
  • 89
Burak
  • 478
  • 1
  • 6
  • 18
1

use this theme in the activity

add this style in your style.xml

<style name="aAppTheme" parent="android:Theme.Wallpaper">
    <item name="android:background">@color/Black</item>
</style>

add this line to the manifest manifest.xml

<activity
android:name="yourpackagename.activityname"
android:label="@string/app_name"
android:theme="@style/aAppTheme" 
>

regards maven

Maveňツ
  • 1
  • 12
  • 50
  • 89