我正在开发的应用程序在第一次安装时有一种奇怪的行为.如果用户第一次正常退出应用程序,它将永远按预期运行.如果用户在安装应用程序后第一次使用主页按钮,它会将应用程序视为应该再次重新启动主屏幕并在旧版本之前启动新版本的活动.
所以手头有两个问题.我似乎无法解决这两个问题.
我没有launchMode将清单文件中的属性定义为任何内容.因此,不应该有任何奇怪的行为.我现在已经尝试launchmode了应用程序的属性,看看我是否能够按照预期的方式运行它,但是这里似乎还有更多的东西,而不仅仅是正确地启动活动.当我按下主页按钮时,应用程序应该第一次关闭自己是没有理由的.
我也没有onUserLeaveHint 在应用程序中使用.通过对项目进行搜索,我必须再次确定.所以似乎根本没有尝试覆盖主页按钮.
即使重新启动手机,主页按钮也会再次正常运行.不确定是什么原因导致初始安装将主页按钮视为从头开始启动应用程序的标志.
一旦用户第一次退出应用程序,问题就会永久解决.关于我应该在哪里看的任何想法?
最近在应用程序中进行了一次搜索,以查看是否它只是因为onUpgrade()SQLite数据库方法的一个组件导致一些奇怪的行为而触发.
@Override
public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion) {
if (newVersion > oldVersion) {
}
}
Run Code Online (Sandbox Code Playgroud)
或者在另一个可能触发清单文件更新的位置,如果我将新版本的APK传递给其上有版本的设备已经低于当前版本.但是,在这部分代码中没有任何内容让我相信它应该影响与启动序列相关的任何事情.
清单文件(名称已更改)在下面提供,用于应用程序当前使用的内容.
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="com.android.vending.CHECK_LICENSE"></uses-permission>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.VIBRATE" android:required="false"/>
<uses-permission android:name="android.permission.CAMERA" android:required="false"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
<application android:icon="@drawable/icon"
android:label="@string/app_name"
android:allowBackup="false"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
>
<activity android:name=".MyMain"
android:label="@string/app_name_with_version"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity android:name=".StartupActivity"
android:label="@string/app_name"
android:screenOrientation="portrait" …Run Code Online (Sandbox Code Playgroud) 我的应用状态栏中有通知:
Notification notification = new Notification(R.drawable.icon, null, System.currentTimeMillis());
Intent notificationIntent = new Intent(this.parent, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this.parent, 0, notificationIntent, 0);
...
notification.flags = Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(NOTIFICATION_ID, notification);
Run Code Online (Sandbox Code Playgroud)
这个问题是当你从应用程序按下主页按钮(将其推到后台),然后按下从状态栏访问的列表中的通知,它会启动活动的新副本.我想要做的就是恢复应用程序(比如当你长按主页按钮并按下应用程序的图标时).有没有办法创建一个Intent来做到这一点?
我已经创建了一个管理短信的应用程序,我已经创建了通知,但是当我点击它们时它启动了另一个活动,我想知道如何检查一个活动是否已经停止并恢复它.
以下是用于创建pendingintent的代码:
private void createNotification(SmsMessage sms, Context context){
final NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
String contentTitle = "";
// construct the Notification object.
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(contentTitle)
.setContentText(sms.getMessageBody())
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(getIconBitmap())
.setNumber(nmessages);
builder.setAutoCancel(true);
//(R.drawable.stat_sample, tickerText,
// System.currentTimeMillis());
// Set the info for the views that show in the notification panel.
//notif.setLatestEventInfo(this, from, message, contentIntent);
/*
// On tablets, the ticker shows the sender, the first line of the message,
// the photo of the person and the app icon. …Run Code Online (Sandbox Code Playgroud) 我想通过点击状态栏中的通知来打开上次启动的活动.假设我启动了活动A(我的应用程序的主要活动),此活动会向通知状态栏发送通知.活动A还打开活动B,B打开另一个活动C.从C i按主页按钮.现在我想再次访问我的应用程序,所以从通知栏我点击通知(由A发送).这里通知应该启动活动C,因为它是上次打开的.
我对此进行了搜索但未找到正确的答案.提前致谢.
我的目标是,如果用户点击通知,则返回上一个活动.我以这种方式在服务onCreate()中创建通知:
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Run Code Online (Sandbox Code Playgroud)
但是当我点击通知时,这将转到MainActivity而不是之前打开的最后一个单击主页按钮.
在清单中,我尝试使用launchMode ="singleTop","standard"和"singletask"来使用MainActivity,但没有成功.
谢谢.