android - Sending data to fragment from service -
android - Sending data to fragment from service -
i have string in service, , want send fragment. seems onreceive() method on broadcastreceiver never called, , can't figured out why. answers.
my service class
public class servis extends service { static final string map = "myservice"; static final string userid = ""; public static final string filepath = "filepath"; @override public int onstartcommand(intent intent, int flags, int startid) { system.out.println("starting service"); toast.maketext(this, "service starting", toast.length_short).show(); string id = intent.getstringextra("userid"); system.out.println(id); intent intent1 = new intent(map); intent1.putextra(userid, id); sendbroadcast(intent1); homecoming start_redeliver_intent; } @override public ibinder onbind(intent intent) { homecoming null; } @override public void oncreate() { toast.maketext(this, "my service created", toast.length_long).show(); log.d(map, "oncreate"); } @override public void ondestroy() { toast.maketext(this, "my service stopped", toast.length_long).show(); log.d(map, "ondestroy"); } @override public void onstart(intent intent, int startid) { toast.maketext(this, "my service started", toast.length_long).show(); log.d(map, "onstart"); }
}
my fragment class
package com.example.mobilproje; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.content.intentfilter; import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.widget.toast; import com.google.android.gms.maps.cameraupdatefactory; import com.google.android.gms.maps.googlemap; import com.google.android.gms.maps.supportmapfragment; import com.google.android.gms.maps.model.latlng; import com.google.android.gms.maps.model.markeroptions; public class mapfragment extends fragmentactivity{ private googlemap googleharita; private broadcastreceiver receiver = new broadcastreceiver() { @override public void onreceive(context context, intent intent) { bundle bundle = intent.getextras(); handleresult(bundle); } }; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.map_fragment); registerreceiver(receiver, new intentfilter( servis.map)); if (googleharita == null) { googleharita = ((supportmapfragment) getsupportfragmentmanager().findfragmentbyid(r.id.haritafragment)) .getmap(); if (googleharita != null) latlng evkoordinat = new latlng(40.7994211,29.9517352); googleharita.addmarker(new markeroptions().position(evkoordinat).title("ev")); googleharita.movecamera(cameraupdatefactory.newlatlngzoom(evkoordinat, 13)); } } } @override public void onresume() { registerreceiver(receiver, new intentfilter( servis.map)); } private void handleresult(bundle bundle) { if (bundle != null) { string string = bundle.getstring(servis.userid); system.out.println("string"); } } }
androidmanifest
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.mobilproje" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="13" android:targetsdkversion="23" /> <uses-permission android:name="android.permission.nfc" /> <uses-permission android:name="com.google.android.providers.gsf.permission.read_gservices" /> <uses-feature android:glesversion="0x00020000" android:required="true" /> <application android:allowbackup="true" android:icon="@drawable/nfc" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:theme="@style/mytheme" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.tech_discovered" /> <action android:name="android.nfc.action.ndef_discovered" /> <action android:name="android.nfc.action.tag_discovered" /> </intent-filter> <meta-data android:name="android.nfc.action.tech_discovered" android:resource="@xml/nfc_tech_filter" /> </activity> <activity android:name=".mapfragment" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <meta-data android:name="com.google.android.maps.v2.api_key" android:value="aizasycgppczppqa_00_v-ntux_wuguao9egupc" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <service android:enabled="true" android:name=".servis" android:process=":localservice"/> </application> <uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.access_network_state"/> <uses-permission android:name="android.permission.write_external_storage"/> </manifest>
android broadcastreceiver android-service android-broadcast
Comments
Post a Comment