为什么我的应用程序需要两次才能打开?
由于某种原因,我的应用程序第一次打开时失败,但第二次单击它时打开正常。发生这种情况有什么常见原因吗?
这是主要活动的代码,任何信息将不胜感激:
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);
}
});
}
}
清单文件:
<?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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案来自包管理器。事实证明,如果您最后不写 PackageManager.DONT_KILL_APP ,它会关闭应用程序,如下所示:
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:
尝试仅保留一项活动作为启动器。从此处删除此行
Try to leave only one activity as launcher. Remove this row
<category android:name="android.intent.category.LAUNCHER" />
from here我遇到了同样的问题,这不是最好的方法,但对我有用!
I had same issue, is not the best way but work for me!