Christian
Christian

Reputation: 755

Why does my app take twice to open?

My app for some reason fails the first time it opens, but then opens fine the second time I click on it. Are there any common reasons this happens?

Here is the code for the main activity, any information would be greatly appreciated:

package com.chich;

import android.app.Activity;

import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class chich_activity extends Activity 
{

Button btnSendSMS;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);  

    ComponentName locationReceiver = new ComponentName(this, SmsReceiver.class);
    PackageManager pm = getPackageManager();
    pm.setComponentEnabledSetting(locationReceiver,
            PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);



    btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
    btnSendSMS.setOnClickListener(new OnClickListener() 
    {


        public void onClick(View v) 
        {     
            Intent i = new Intent(chich_activity.this, chich_activity2.class);
            startActivity(i);

    }    
});
    }
}

Manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.chich"
  android:versionCode="1"
  android:versionName="1.0.0">
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
    <activity android:name=".chich_activity"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>     

       <activity android:name=".chich_activity2"
              android:label="@string/app_name">
        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity> 

    <receiver android:name=".SmsReceiver"> 
        <intent-filter android:priority="9999999" >
            <action android:name = "android.provider.Telephony.SMS_RECEIVED" /> 
        </intent-filter> 
    </receiver>

</application>
<uses-permission android:name="android.permission.SEND_SMS">
</uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS">
</uses-permission>
</manifest>

Upvotes: 2

Views: 1631

Answers (3)

Jose A. de los Santos
Jose A. de los Santos

Reputation: 45

I had same issue, is not the best way but work for me!

 switch(estado) {
                case 0:
                    if (!tcursor.moveToFirst()){
                        estado = 1;

                            Intent intentConfig=new Intent(getApplicationContext(),Configuracion.class);
                            startActivity(intentConfig);
                    }
                    break;
                default:

            }

Upvotes: 0

Christian
Christian

Reputation: 755

The answer came in the package manager. Turns out it shuts the application off if you don't write in the end, PackageManager.DONT_KILL_APP as in:

ComponentName locationReceiver = new ComponentName(this, SmsReceiver.class);
PackageManager pm = getPackageManager();
pm.setComponentEnabledSetting(locationReceiver,
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Upvotes: 1

Nataliia.dev
Nataliia.dev

Reputation: 2972

Try to leave only one activity as launcher. Remove this row <category android:name="android.intent.category.LAUNCHER" /> from here

<activity android:name=".chich_activity2"
              android:label="@string/app_name">
        <intent-filter>
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity> 

Upvotes: 0

Related Questions