Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 正在将数据从服务检索到活动OnResume()_C#_Android_Service_Xamarin.android_Xamarin - Fatal编程技术网

C# 正在将数据从服务检索到活动OnResume()

C# 正在将数据从服务检索到活动OnResume(),c#,android,service,xamarin.android,xamarin,C#,Android,Service,Xamarin.android,Xamarin,我已经被一个问题困扰了一段时间了。“我的活动”使用“活动”OnPause()中的ServiceName.PutExtra(名称、值)启动并向我的服务发送数据(DT start、DT finish、Char action),但它还需要读取相同的新值 该活动使用GPS记录设备何时移动和何时不移动,以及这些移动的开始和结束时间 当我回到我的活动OnResume()需要读取服务当前记录的内容时,请继续此记录并停止服务 我已经阅读了很多关于绑定服务的内容,但无法使用简单的代码示例和解释(来源于@Xamar

我已经被一个问题困扰了一段时间了。“我的活动”使用“活动”
OnPause()
中的
ServiceName.PutExtra(名称、值)
启动并向我的服务发送数据(DT start、DT finish、Char action),但它还需要读取相同的新值

该活动使用GPS记录设备何时移动和何时不移动,以及这些移动的开始和结束时间

当我回到我的活动
OnResume()
需要读取服务当前记录的内容时,请继续此记录并停止服务

我已经阅读了很多关于绑定服务的内容,但无法使用简单的代码示例和解释(来源于@Xamarin站点、android开发者站点、stackoverflow)

有人能告诉我一个代码,其中明确说明了服务活动之间的绑定,以及如何将数据从服务获取到活动OnResume()


我使用Xamarin和C#,但如果需要,我可以从java代码中进行调整

我已经很长时间没有使用它了(因为我现在使用LocalBroadcasts来实现这个目的),所以我可能会错过一些东西,但通常情况下(在java中)是这样的:

在活动中:

/** Defines callbacks for service binding, passed to bindService() */
private ServiceConnection mConnection = new ServiceConnection() {

public void onServiceConnected(ComponentName arg0, IBinder service) {
    LocalBinder binder = (LocalBinder) service;
    mStateChecker = binder.getService();
    mBound = true;

    Intent intent2 = getIntent();
    finish();
    startActivity(intent2); 
}


public void onServiceDisconnected(ComponentName arg0) {
     mBound = false;

     Intent intent2 = getIntent();
     finish();
     startActivity(intent2);

    }   
};




 //start the service & bind to it
    startService(new Intent(this, StateChecker.class));
    Intent intent = new Intent(this, StateChecker.class);
    bindService(intent, mConnection, Context.BIND_AUTO_CREATE); 
在职:

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

/**
 * Class used for the client Binder.  Because we know this service always
 * runs in the same process as its clients, we don't need to deal with IPC.
 */
public class LocalBinder extends Binder {
    StateChecker getService() {    //  StateChecker is the name of this class
        // Return this instance of LocalService so clients can call public methods
        return StateChecker.this;
    }
}

感谢您的帮助,但我无法让它正常工作。。。。只考虑在不交换数据的情况下绑定它(在活动进行时保持服务活动),并使用广播来传输数据。