如何从呼叫服务,通知栏活动 [英] How to call an activity from service with Notification Bar
问题描述
这是我的sistuation
This is my sistuation
A1 =闪屏活动
A2 =主要活动
A3 =额外活动
S1 = GPS服务
S1 = GPS Service
我开始与创建意图推出A2和A1,然后完成A1。
A2的内部创建和绑定S1(S1里面我做一个通知)
I start with A1 that creates intent to launch A2 and then A1 finish. Inside A2 I create and bind S1 (Inside S1 I make a Notification)
CharSequence text = getText(R.string.local_service_started);
Notification notification = new Notification(R.drawable.notify_icon, text, System.currentTimeMillis());
Intent i = new Intent();
i.setClassName("xxx.yyy.zzz.kkk", "xxx.yyy.zzz.kkk.A2");
i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(this, getText(R.string.local_service_label), text, contentIntent);
mNM.notify(NOTIFICATION, notification);
现在我有我的通知栏图标
如果我preSS HOME键我A2的活动内,打开另一个应用程序,然后我preSS我的通知图标都正常工作,我门背我A2的活性(A2是最上面的活动),但如果里面A2我启动A3和回家,preSS通知我有问题,A2创建为一个新的实例(A2现在还不是最上面的)!可能有这样长的$ P $ HOME PSS的影响,我的重点应用程序内的最后一次公开活动?我不想打开特定的活动,但带给我的前暂停活动不活动的新实例。
Now I have my icon in the notification bar If I press HOME button inside my A2 activity and open another application and then I press my notification icon all is working correctly and I gate back my A2 activity(A2 is the top most activity), but if inside A2 I launch A3 and go back HOME and press the notification I have the problems, A2 is created as a new instance(A2 now isn't top most)! Is possible to have the effect like long press HOME and focus the last open activity inside my application? I don't want to open a specific activity, but bring to front my paused activity without a new instance of the activity.
推荐答案
我已经解决了,这打开我的应用程序preserving的实际状态,并获得开业活动形式回后台foregraund。照此想起应用选择从最近通话!
I have solved, this open my application preserving the actual state and get the opened activity back form background to foregraund. Do the same think of app selecting from RECENTS !
Intent i = new Intent();
i.setAction(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
i.setComponent(new ComponentName(getApplicationContext().getPackageName(), MyAppClass.class.getName()));
MyAppClass是您的APK推出的第一个活动。
MyAppClass is the 1st Activity your APK is launching.
最好的问候
这篇关于如何从呼叫服务,通知栏活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!