John smith
John smith

Reputation: 353

Android keyboard and activity background

I have two activities.

In the first one I have a button like this :

button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        startActivity(new Intent(this, Activity2.class));
    }
});

Then in my SecondActivity, I have a EditText.

But when I tap on the EditText, the keyboard is well showing but I can see the view of the FirstActivity during the keyboard slide animation. Is that normal ? I don't think so .. So I'm trying to understand what I have done wrong ..

Manifest.xml

<activity
    android:name=".activities.Activity1"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"/>

<activity
    android:name=".activities.Activity2"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Translucent.NoTitleBar"
    android:windowSoftInputMode="adjustResize"/>

Thanks in advance !

Upvotes: 0

Views: 148

Answers (1)

Charuka Silva
Charuka Silva

Reputation: 13153

If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish, or simply killing its process. When it is displayed again to the user, it must be completely restarted and restored to its previous state.

onDestroy() is the final call you receive before your activity is destroyed. This can happen either because the activity is finishing (someone called finish() on it, or because the system is temporarily destroying this instance of the activity to save space. You can distinguish between these two scenarios with the isFinishing() method.

And for your question you have a android:theme="@android:style/Theme.Translucent.NoTitleBar" which display transparent activity that is the reason to display your previous activity behind because the background is transparent and you have not finished the previous activity, so you see it. If you finish it i doubt you might see the mobile screen as well if you don't have any back states

I don't know your requirement depending on that you can,

  1. Change the transparent Theme
  2. Remove previous activity from back state
  3. Go with 1 & 2

Upvotes: 1

Related Questions