【发布时间】:2014-12-11 18:08:44
【问题描述】:
我从虚拟项目测试服务和通知中复制了一段代码,其中重新编码器到字体的工作就像一个魅力。
这是通知的代码(与教程中的非常相似)
NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentTitle("Request awaiting")
.setContentText("There is a service request awaiting for Your reaction");
Intent resultIntent = new Intent(this, MainActivity.class);
resultIntent.setAction(Intent.ACTION_MAIN);
resultIntent.addCategory(Intent.CATEGORY_LAUNCHER);
resultIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);//stackBuilder.getPendingIntent(0, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
nBuilder.setContentIntent(resultPendingIntent);
NotificationManager mNotificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = nBuilder.build();
mNotificationManager.notify(1, notification);
清单看起来像:
<application android:allowBackup="true" android:icon="@drawable/ld"
android:label="@string/app_name" android:theme="@style/AppTheme">
<activity
android:name="com.iraasta.cloudcab.driver.MainActivity"
android:launchMode="singleTop"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
它在我的其他应用程序中看起来完全一样,它完美地将应用程序带到前面,就像从主屏幕选择时一样。 但在这一次中,它每次都调用 OnCreate 并失去整个状态。
【问题讨论】:
-
你的应用有透明/半透明的主题吗?
-
如果您要问的话,它会在具有 Android 按钮栏样式的按钮上使用透明样式
-
如果活动具有透明背景,有一个已知错误会破坏 FLAG_ACTIVITY_REORDER_TO_FRONT 的功能。也许那不是你的问题。由于您尝试启动的活动是您的根 (LAUNCHER) 活动,您为什么要在这里设置后台堆栈?没有家长活动。也许这是导致问题的原因?
-
我只是复制了官方android通知教程中使用的所有代码
-
我的应用是单一活动
标签: android android-intent notifications