相关疑难解决方法(0)

clear最近的应用程序擦除应用程序内存,我的接收器停止工作

如果在背景中,MyApp的接收器工作正常,它是:

    public class MySmsReceiver extends WakefulBroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        System.out.println("triggered sms");
        if(intent.getAction().equals(Telephony.Sms.Intents.SMS_RECEIVED_ACTION)) {
          Toast.makeText(context, "message Received", Toast.LENGHT_SHORT).show();
    }
}
Run Code Online (Sandbox Code Playgroud)

我的接收器清单文件是

        <receiver android:name=".MySmsReceiver">
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />

        </intent-filter>
    </receiver>
Run Code Online (Sandbox Code Playgroud)

文件说,如果我在清单文件中声明一个接收器,它应该始终有效.但就我而言,它不是......

但每当我通过刷它清除我最近的应用程序时它就停止了工作.在我去任务管理员后看到MyApps强制停止如下所示 taskmanager中我的应用程序的屏幕截图

我想出了一些应用程序,如watsapp和fb总是留在内存中说这个bcoz刷完清楚的最近的应用程序仍然任务管理器有如下所示的跟随状态

任务管理器中的fb状态

任务管理员中的watsapp状态

我怎么能在我的应用程序中执行此操作..什么会使我的应用程序像其他第三方应用程序,如watspp和Facebook ...我怎么能让我的应用程序在内存中总是我问这个然后只有我的接收器将始终工作..如果我错了,请给我一个解决方案来做到这一点......

我一直在搜索这个问题但仍然无法找到解决方案...我错了吗?还是真的有办法做到这一点?请有人帮帮我...这让我一周!!! 希望我在这里解释我的问题,如果我不问我,我会立即给你答复.

service android taskmanager broadcastreceiver google-cloud-messaging

25
推荐指数
2
解决办法
7253
查看次数

即使应用程序被强制停止也会重新启动服务,即使在关闭应用程序后仍然在后台继续运行服务如何?

我正在尝试在后台运行服务.我的应用程序所做的是当用户检查复选框然后服务启动时以及取消选中时服务停止.哪个工作得很好.但问题是,当我从任务管理器关闭应用程序时,它也会停止服务.我想要的是即使它从任务管理器关闭后仍保持服务运行.然后,只有通过取消方框才能让用户自己停止该服务.

我怎样才能做到这一点?

这是我的代码

我的主要活动

public class SampleServiceActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final CheckBox cb = (CheckBox) findViewById(R.id.checkBox1);

    cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView,
                boolean isChecked) {

            if(isChecked) {
                Toast.makeText(getBaseContext(), "Checked", Toast.LENGTH_LONG).show();
                startService(new Intent(getBaseContext(), MyService.class));
            } else {
                Toast.makeText(getBaseContext(), "Unchecked", Toast.LENGTH_LONG).show();
                stopService(new Intent(getBaseContext(), MyService.class));
            }
        }

    });
}
}
Run Code Online (Sandbox Code Playgroud)

我的服务类

public class MyService extends Service {
Notify n = new Notify();
@Override
public IBinder …
Run Code Online (Sandbox Code Playgroud)

java android android-service

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

Cordova ibeacon; 在应用程序被杀后发送本地通知,但在android上无效

我正在我的cordova项目中使用Cordova/Phonegap iBeacon插件ionicframework.当应用程序被杀死时,我正在尝试使用cordova本地通知插件在android和ios上发送本地通知.

这是我的代码:

document.addEventListener("deviceready", onDeviceReady, false);

    function didDetermineStateForRegion(pluginResult) {
    }

    function didStartMonitoringForRegion (pluginResult) {
    }
    function didExitRegion(pluginResult) {
        $cordovaLocalNotification.add({
        id: 30244234234,
        title: "Good By!",
        text: "Hope to see you again."
            }).then(function () {
            });
    }

    function didEnterRegion (pluginResult) {
        $cordovaLocalNotification.add({
        title: "Welcome",
        text: "Tap to launch app"
            }).then(function () {

            });

    };
    function didRangeBeaconsInRegion (pluginResult) {

    }

    function onDeviceReady() {
        // Now safe to use device APIs
        function createBeacon(uuid,nofiyState) {

            var uuid = uuid; …
Run Code Online (Sandbox Code Playgroud)

javascript android cordova ibeacon ionic-framework

14
推荐指数
1
解决办法
4348
查看次数

强制停止后开始服务

用户使用设置 - >应用程序 - >管理应用程序 - >我们的应用程序 - >强制停止后,有没有办法启动服务
.

我想在强制关闭后重启我的应用程序.

有没有办法做同样的事情?

android

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

在刷掉应用程序时,Android服务会被杀死

我有一个Android Service类,其代码如下:

public class LoginService extends Service {
BroadcastReceiver wifiStateChangeReciever;

@Override
public IBinder onBind(Intent arg0) {
    return null;
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("AndroidLearning", "Service onStartCommand Started.");
    return Service.START_STICKY;
}

@Override
public void onCreate() {
    super.onCreate();
    Log.i("AndroidLearning", "Service Started.");

    final IntentFilter intentFilter = new IntentFilter();
    // intentFilter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
    intentFilter.addAction("android.net.wifi.STATE_CHANGE");
    wifiStateChangeReciever = new WifiStateChangeReciever();
    this.registerReceiver(wifiStateChangeReciever, intentFilter, null, null);

    Log.i("AndroidLearning", "Reciever Registered.");
}

@Override
public void onDestroy() {
    Log.i("AndroidLearning", "Service Destroyed.");
    this.unregisterReceiver(wifiStateChangeReciever);
}

@Override
public void onTaskRemoved(Intent …
Run Code Online (Sandbox Code Playgroud)

service android

4
推荐指数
1
解决办法
4636
查看次数