相关疑难解决方法(0)

如何使通知意图恢复而不是制定新的意图?

我在这里有一个简单的webview活动,加载后它会自动显示正在进行的通知.我们的想法是,人们可以远离此活动,并通过下拉菜单并选择它,从他们想要的任何屏幕再次快速访问它.然后,当他们想要时,他们可以通过点击菜单按钮并点击退出来关闭通知,然后清除通知.一切正常.但是,当按下通知时,它会启动活动的新实例.我需要更改什么才能看到活动是否尚未被销毁,我可以回调用该实例(恢复它),因此不需要再次加载它,也不需要在我的堆栈中添加其他活动.有任何想法吗?任何帮助将不胜感激.

package com.my.app;

import com.flurry.android.FlurryAgent;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent; 
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.CookieSyncManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class Chat extends Activity { 
    private ProgressDialog progressBar;
    public WebView webview;
    private static final String TAG = "Main";

    private NotificationManager mNotificationManager;
    private int SIMPLE_NOTFICATION_ID;

    @Override
    public void onStart() {
       super.onStart();
       CookieSyncManager.getInstance().sync();
       FlurryAgent.onStartSession(this, "H9QGMRC46IPXB43GYWU1");
    }

    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); …
Run Code Online (Sandbox Code Playgroud)

resume notifications android android-intent android-activity

39
推荐指数
3
解决办法
5万
查看次数

从通知中恢复活动

我的应用状态栏中有通知:

    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来做到这一点?

java notifications android android-activity

35
推荐指数
1
解决办法
1万
查看次数

意图恢复以前暂停的活动(从通知中调用)

我正在开发一个向用户显示通知的应用程序.通知的目的是使用户在另一个活动中轻松返回活动.我在我的应用程序中使用此代码来创建和显示通知.

                    notification = new Notification(R.drawable.icon,
                            "Notify",
                            System.currentTimeMillis());
                    notification.setLatestEventInfo(this, "App name",
                            "App message",
                            PendingIntent.getActivity(
                                    this, 0,
                                    new Intent(this, Main.class),
                                    PendingIntent.FLAG_CANCEL_CURRENT));
                    notification.flags |= Notification.FLAG_ONGOING_EVENT;
                    nManager.notify(0, notification);
Run Code Online (Sandbox Code Playgroud)

但是当用户点击通知时,会启动相同活动的新实例,而不是之前用户使用的实例.

我认为这与PendingIntent有关,但是我找不到如何使Intent恢复以前暂停的活动实例而不是创建新实例.

谢谢.

notifications android android-activity android-pendingintent

21
推荐指数
3
解决办法
2万
查看次数

通知恢复活动

我知道,有几个这种类型的问题,但我尝试了所有这些,但它仍然无效.
好的,对于我的应用; 我有一个活动.在此活动中,有4个选项卡,第四个包含列表和记录按钮.当我推送记录时,有一个GPS监听器启动.获取新的gps值后,它会将其推送到列表中.
到目前为止这个工作!
如果我单击主页按钮它仍然有效,如果我长按它.它恢复了具有特定Tab的Activity,并且列表仍然保持listitems并且gps监听器仍处于活动状态.
这个工作也没关系!
现在我想添加一个通知,它将列表的gps值计数显示为.number.在每个新的gps信号上,它会使用新号码更新通知图标.这没问题,但点击通知的动作完全搞砸了我的申请.

实际代码如下所示:

public void callNotify(String text) {
    notif = new Notification();
    Intent contentIntent = new Intent(this, tabactivity.class);
    contentIntent.putExtra("fid", this.specialvalue);
    contentIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
        | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    notif.icon = R.drawable.icon;
    notif.setLatestEventInfo(this, getString(R.string.app_name), text,
        PendingIntent.getActivity(this.getBaseContext(), 0, contentIntent,
            PendingIntent.FLAG_UPDATE_CURRENT));
    notif.ledARGB = Color.RED;
    notif.ledOnMS = 200;
    notif.ledOffMS = 200;
    notif.flags = Notification.FLAG_SHOW_LIGHTS
        | Notification.FLAG_ONGOING_EVENT
        | Notification.FLAG_ONLY_ALERT_ONCE;
    notif.number = notifyNumber;
    mNotificationManager.notify(notifyNumber, notif);
}

public void updateNotify(String text) {
    notifyNumber++;
    notif.number = (int) (notifyNumber / 2);
    Intent contentIntent = new Intent(this, tabactivity.class);
    contentIntent.putExtra("fid", this.specialvalue); …
Run Code Online (Sandbox Code Playgroud)

resume notifications android

9
推荐指数
1
解决办法
1万
查看次数

Android:从以前的位置恢复应用程序

如何从以前的位置恢复我的应用程序.

请注意,它仍处于活动状态,只是暂停了.因此,如果我单击androids当前应用程序按钮或应用程序图标,它将恢复正常.

但我是谁从我的小部件做到这一点..

我有以下内容:

// Create an Intent to launch Activity
Intent intent = new Intent(context, LoginForm.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
Run Code Online (Sandbox Code Playgroud)

这显然启动了LoginForm,而不仅仅是恢复应用程序.

有谁知道如何做到这一点?

编辑:

只是为了澄清,我不想要任何特别的东西.我基本上想模仿按下android图标启动器.

android android-intent

9
推荐指数
1
解决办法
5380
查看次数

android如何在点击通知时打开上一个活动

我观察过几个类似的问题,但他们无法帮助我.我需要在用户点击通知时显示上次活动.这是我的代码:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(YourService.this)
        .setContentTitle(getResources().getText(R.string.app_name))
        .setContentText(getServiceStateDescription(YourService.this))
        .setSmallIcon(iconId)
        .setWhen(System.currentTimeMillis());

Intent nIntent = getPreviousIntent();
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack
stackBuilder.addParentStack(MainActivity_.class);
stackBuilder.addNextIntent(nIntent);
PendingIntent pendingIntent =
        stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setContentIntent(pendingIntent);

startForeground(ContextConstants.LAUNCHER_SERVICE_NOTE_ID, notificationBuilder.build());


private Intent getPreviousIntent() {
Intent newIntent = null;
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    final List<ActivityManager.AppTask> recentTaskInfos = activityManager.getAppTasks();
    if (!recentTaskInfos.isEmpty()) {
        for (ActivityManager.AppTask appTaskTaskInfo: recentTaskInfos) {
            if (appTaskTaskInfo.getTaskInfo().baseIntent.getComponent().getPackageName().equals(ContextConstants.PACKAGE_NAME)) {
                newIntent = appTaskTaskInfo.getTaskInfo().baseIntent;
                newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
        }
    }
} else {
    final List<ActivityManager.RecentTaskInfo> …
Run Code Online (Sandbox Code Playgroud)

notifications android android-pendingintent

7
推荐指数
1
解决办法
4324
查看次数