Updating RecyclerView with adapter.notifyDataSetChanged() - java

I've implemented a RecyclerView which has a user interface of a timer counting down. I created a BroadcastService class which creates a CountDownTimer and broadcasts the timer's contents in the onTick() method to my MainActivity, where I use a BroadCast receiever to update the UI.
My BroadcastReceiver is only receiving the initial value from the BroadcastService. I figured that's because I hadn't notified the recycler view's adapter that the data had changed. However, because of variable scope, I'm unable to access my adapter from my broadcast receiver.
Perhaps I have a fundamental lack of understanding of variable scope, but how can I access the adapter from
adapter = new DataAdapter(getApplicationContext(), data);
in my broadcast receiver class? Because right now it's not being recognized.
This is my class definition + onCreate()
public class Profile_Page extends ActionBarActivity implements DataAdapter.ClickListener {
private RecyclerView recyclerView;
public DataAdapter adapter;
private Context context;
String currentUser;
Data current = new Data();
final List<Data> data = new ArrayList<>();
public static String BROADCAST_ACTION =
"packagename.countdown_br";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
IntentFilter filter = new IntentFilter();
filter.addAction(BROADCAST_ACTION);
filter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(br, filter);
startService(new Intent(this, Broadcast_Service.class));
setContentView(R.layout.activity_profile__page);
ParseQuery<ParseObject> query = ParseQuery.getQuery("ParseClass");
query.whereEqualTo("author", ParseUser.getCurrentUser());
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
query.findInBackground(new FindCallback<ParseObject>() {
#Override
public void done(List<ParseObject> list, ParseException e) {
if (e == null) {
for (ParseObject getData : list)
{
current.1= getData.getString("1");
current.2= getData.getString("2");
current.3= getData.getString("3");
current.4= getData.getString("4");
current.5= getData.getString("5");
data.add(current);
}
}
else {
}
adapter = new DataAdapter(getApplicationContext(), data);
recyclerView.setAdapter(adapter); //set recyclerView to this adapter
}
});
}
And here's my Broadcast Receiver code [which is also in MainActivity.java]
public BroadcastReceiver br = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
updateGUI(intent);
//HOW TO NOTIFY DATA SET CHANGE
}
};
public void updateGUI(Intent intent) {
if (intent.getExtras() != null) {
long millisUntilFinished = intent.getLongExtra("countdown", 0);
current.goalTimer = String.valueOf(intent.getExtras().getLong("countdown") / 1000);
}
}
And, if it is of any use, here's my Broadcast Service class:
public class Broadcast_Service extends Service {
private final static String TAG = "BroadcastService";
LocalBroadcastManager broadcastManager;
public static final String COUNTDOWN_BR = "packagename.countdown_br";
Intent bi = new Intent(COUNTDOWN_BR);
CountDownTimer cdt = null;
#Override
public void onCreate() {
super.onCreate();
Log.i(TAG, "Starting timer...");
cdt = new CountDownTimer(30000, 1000) {
#Override
public void onTick(long millisUntilFinished) {
bi.putExtra("countdown", millisUntilFinished);
sendBroadcast(bi);
}
#Override
public void onFinish() {
Log.i(TAG, "Timer finished");
}
};
cdt.start();
}
#Override
public void onDestroy() {
cdt.cancel();
Log.i(TAG, "Timer cancelled");
super.onDestroy();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
#Override
public IBinder onBind(Intent intent) {
return null;
}
}

First of all, extend the BroadcastReciever class as follows:
public class MyReciever extends BroadcastReciever{
private Profile_Page activity;
public MyReciever(Profile_Page activity){
this.activity = activity;
}
#Override
public void onReceive(Context context, Intent intent) {
activity.updateGUI(intent);
}
}
Create a static instance of your activity and pass it to your receiver.
public class Profile_Page extends ActionBarActivity implements DataAdapter.ClickListener {
private static Profile_Page instance;
private MyReciever myReceiver;
...
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
instance = this;
myReceiver = new MyReciever(instance);
...
}
public void updateGUI(Intent intent) {
...
}
}
Now you can access your adapter quite easily. Hope this helps.

Related

how to pause mp3 using mediaplayer in another activity when an item is clicked?

i'm make mp3 player offline, in the MainActivity there is a song list when an item is clicked it will send the song data with intent to PlayActivity. I want when another song is clicked then the current song is paused. What should i do? below is my code
MainActivity
public class MainActivity extends AppCompatActivity {
//deklarasi variabel -->
MediaPlayer mediaPlayer;
ListView listView;
final String[] song_name = { "intuisi", "krisis solusi" };
final int[] ResID = {R.raw.intuisi, R.raw.krisis};
ImageView img_play;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//inisialisasi variabel
mediaPlayer = new MediaPlayer();
listView = findViewById(R.id.list_item);
//make adapter for listview
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, song_name);
listView.setAdapter(adapter);
//onClick item
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
playSong(i);
}
});
}
private void playSong(int songIndex) {
//send song data to playActivity
Intent intent = new Intent(MainActivity.this, Play.class);
intent.putExtra("song", ResID[songIndex]);
startActivity(intent);
}
PlayActivity
int Nama = getIntent().getIntExtra("song",0);
mediaPlayer = MediaPlayer.create(getApplicationContext(), Nama);
if (mediaPlayer != null && mediaPlayer.isPlaying()) {
mediaPlayer.pause();
} else {
mediaPlayer.start();
}
You can create a separate singleton helper class for handling your music player with some contextual method like play, pause, stop etc.
public class MusicHelper {
private static MusicHelper instance;
MediaPlayer mPlayer;
private MusicHelper() {
instance = new MusicHelper();
}
public static MusicHelper getInstance() {
return instance;
}
public void init(Context ctx, int nama) {
mPlayer = MediaPlayer.create(getApplicationContext(), nama);
}
public void play() {
if (mPlayer != null && !mPlayer.isPlaying()) {
mPlayer.start();
}
}
public void pause() {
if (mPlayer!= null && mPlayer.isPlaying()) {
mPlayer.pause();
}
}
}
Then in your PlayActivity,
MusicHelper musicHelper = MusicHelper.getInstance();
musicHelper.init(getApplicationContext(), Nama);
musicHelper.play();
When clicked on another item, again fetch the helper instance and call pause.
private void playSong(int songIndex) {
MusicHelper musicHelper = MusicHelper.getInstance();
musicHelper.pause();
Intent intent = new Intent(MainActivity.this, Play.class);
intent.putExtra("song", ResID[songIndex]);
startActivity(intent);
}

How to access service functions from fragment, which is bound to parent activity in Android?

I have an Android activity with a viewpager fragment. In the onCreate method of the activity, I bind a service to it which constantly runs in the background.
In the fragment, on a certain condition I need to call a function in the service which deals with the condition. What is the correct way to access the service, and call it's functions?
MainActivity.java
public class MainActivity extends AppCompatActivity {
private String TAG = "MainActivity";
DbHelper dbHelper;
SessionManager sessionManager;
SessionCache sessionCache;
Map<String, ?> userDetails;
protected SocketListener socketService;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sessionManager = new SessionManager(getApplicationContext());
// Connect to background socketlistener service
Intent serviceIntent = new Intent(MainActivity.this, SocketListener.class);
startService(serviceIntent);
.
.
.
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText("").setIcon(getResources().getDrawable(R.drawable.profileicon)));
tabLayout.addTab(tabLayout.newTab().setText("").setIcon(getResources().getDrawable(R.drawable.homeicon)));
tabLayout.addTab(tabLayout.newTab().setText("").setIcon(getResources().getDrawable(R.drawable.chaticon)));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
final NonSwipeableViewPager viewPager = (NonSwipeableViewPager) findViewById(R.id.view_pager);
final CustomPagerAdapter pagerAdapter = new CustomPagerAdapter
(getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(pagerAdapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
viewPager.setCurrentItem(1);
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
#Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
#Override
public void onTabUnselected(TabLayout.Tab tab) {
}
#Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
private ServiceConnection serviceConnection = new ServiceConnection() {
#Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
socketService = ((SocketListener.LocalBinder) iBinder).getService();
}
#Override
public void onServiceDisconnected(ComponentName componentName) {
socketService = null;
}
};
}
This is my service. I connect to a server, and constantly listen for updates.
SocketListener.java
package com.example.gopa2000.mobapps;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
import java.net.URISyntaxException;
import io.socket.client.IO;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
public class SocketListener extends Service {
private static String TAG = "SocketListener";
private Socket socket;
public SocketListener() { }
#Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
return localBinder;
}
private final IBinder localBinder = new LocalBinder();
public class LocalBinder extends Binder {
public SocketListener getService(){
Log.i(TAG, "getService: Sitting in local binder.");
return SocketListener.this;
}
public void sendMessage(String message){
socket.emit("match", message);
}
}
#Override
public void onCreate() {
super.onCreate();
}
public void isBoundable(){
Log.i(TAG, "Bind like a baller.");
}
#Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
Runnable connect = new ConnectSocket();
new Thread(connect).start();
return START_STICKY;
}
class ConnectSocket implements Runnable {
#Override
public void run() {
try {
socket = IO.socket(RESTClient.getURL());
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
#Override
public void call(Object... args) {
Log.i(TAG, "call: Connected to backend!");
}
});
socket.connect();
} catch (URISyntaxException e){
Log.e(TAG, "run: ", e);
}
}
}
public Socket getSocket(){
return this.socket;
}
}
And this is the fragment where I would need to call the sendMessage(string).
public class MainViewFragment extends Fragment {
private final String TAG = "MVFragment";
private RecyclerView recyclerView;
private RecyclerView.LayoutManager layoutManager;
private RecyclerView.Adapter adapter;
private SessionManager sessionManager;
private ArrayList<CustomCard> cards;
private CardAdapter cardAdapter;
private Button btn;
private SwipeFlingAdapterView flingContainer;
private Map<String, ?> userDetails;
// hax
private static String userEmail;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.from(getContext()).inflate(R.layout.fragment_main_view, container, false);
.
.
flingContainer.setAdapter(adapter);
flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener(){
.
.
#Override
public void onRightCardExit(Object o) {
.
.
if(match){
// need to call sendMessage from the service here. <------------------------
sessionCache.addToMatchTable(Liker, Likee);
}
}
#Override
public void onAdapterAboutToEmpty(int i) {
}
#Override
public void onScroll(float v) {
}
});
flingContainer.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener(){
#Override
public void onItemClicked(int itemPosition, Object dataObject){
Toast.makeText(getActivity(), "Clicked!", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getActivity().getApplicationContext(), FullScreenCardLayout.class);
startActivity(intent);
}
});
return view;
}
First the method sendMessage(message) should be inside the service not the LocalBinder class
public class SocketListener extends Service {
public void sendMessage(String message){
socket.emit("match", message);
}
}
Second to access activity method from fragment you should create interface inside your fragment
interface MessageSender {
void sendMessage(String message);
}
then implement it in your activity
public class MainActivity extends AppCompatActivity implements MessageSender {
#Override
public void sendMessage(String message) {
// call the service here
socketService.sendMessage(message);
}
}
inside your fragment, implement onAttach() and initialize the interface instance
public class MainViewFragment extends Fragment {
private MessageSender mMessageSenderCallback;
#Override
public void onAttach(Context context) {
super.onAttach(context);
try {
mMessageSenderCallback = (MessageSender) context;
} catch (ClassCastException e) {
// Error, class doesn't implement the interface
}
}
#Override
public void onDetach() {
super.onDetach();
// Remove activity reference
mMessageSenderCallback = null;
}
}
To send a message, call mMessageSenderCallback.sendMessage(message) with your message inside the fragment.

How to close an Activity using push Notification in Firebase?

I am working on Firebase Push Notification and i want to close MainActivity. Application should finish when onMessageReceived() is called. I am also passing the Context but its not working. In this case, I'll send notification when application is opend. My code:
MainActivity.java
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new FirebaseMessagingService(MainActivity.this);
}
}
FirebaseMessagingService.java
public class FirebaseMessagingService extends
com.google.firebase.messaging.FirebaseMessagingService {
Context context;
public FirebaseMessagingService(Context ctx) {
this.context = ctx;
}
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
context.finish();
}
}
You could define a BroadcastReceiver in MainActivity, that calls finish() when triggered:
private final BroadcastReceiver finishReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
finish();
}
};
Register/unregister it when appropriate:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// ...
LocalBroadcastManager.getInstance(getApplicationContext())
.registerReceiver(finishReceiver,
new IntentFilter(FirebaseMessagingService.ACTION_FINISH));
}
#Override
protected void onDestroy() {
LocalBroadcastManager.getInstance(getApplicationContext())
.unregisterReceiver(finishReceiver);
super.onDestroy();
}
And then you just simply have to send a local broadcast from onMessageReceived():
public static final String ACTION_FINISH = "yourpackagename.ACTION_FINISH";
#Override
public void onMessageReceived(RemoteMessage remoteMessage) {
LocalBroadcastManager.getInstance(getApplicationContext())
.sendBroadcast(new Intent(ACTION_FINISH));
}
(FirebaseMessagingService is a Context subclass, there is no need to pass another Context instance to it)

Android Media Player App services

I am developing a media player app that has a bound service to an activity.It works fine when i press the home button or the app switcher and then come back to the app from the recent app, but as i press the back button the activity also ends the Music Service. Please guide me the exact steps that can solve these minor issues, so that i can give media controls to the app.My App has 2 main classes
MyActivity
AudioService
My code is given below.
AudioService.java
public class AudioService extends Service implements
MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener,
MediaPlayer.OnCompletionListener{
// -----------------------------------------Attributes--------------------------------------------------------
private ArrayList<File> songs;
private ArrayList<File> audio;
private MediaPlayer player;
private int songPosn;
private String name="";
private final IBinder musicBind = new AudioBinder();
private Uri trackUri;
private int NOTIFY_ID=1;
// -----------------------------------------------------------------------------------------------------------
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
public void onCreate(){
//create the service
//create the service
super.onCreate();
//initialize position
songPosn=0;
//create player
player = new MediaPlayer();
initMusicPlayer();
}
// to initialize the media class
public void initMusicPlayer(){
//set player properties
player.setWakeMode(getApplicationContext(),
PowerManager.PARTIAL_WAKE_LOCK);
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setOnPreparedListener(this);
player.setOnCompletionListener(this);
player.setOnErrorListener(this);
}
public void setList(ArrayList<File> theSongs){
songs=theSongs;
}
public void setSong(int songIndex){
songPosn=songIndex;
}
public class AudioBinder extends Binder {
AudioService getService() {
return AudioService.this;
}
}
#Override
public IBinder onBind(Intent intent) {
return musicBind;
}
#Override
public boolean onUnbind(Intent intent){
player.stop();
player.release();
return false;
}
#Override
public void onCompletion(MediaPlayer mp) {
}
#Override
public boolean onError(MediaPlayer mp, int what, int extra) {
mp.reset();
return false;
}
#Override
public void onPrepared(MediaPlayer mp) {
//start playback
mp.start();
showNotification();
}
#Override
public int onStartCommand(Intent intent, int flags, int startId){
songPosn = intent.getIntExtra("pos",0);
audio=(ArrayList)intent.getParcelableArrayListExtra("songlist");
name = intent.getStringExtra("name");
Log.e("Service","name"+audio.get(0));
Log.e("Service","position "+songPosn);
return START_STICKY;
}
public void playSong(){
//play a song
player.reset();
Log.e("TRACH the URI",""+trackUri);
trackUri =Uri.parse(audio.get(songPosn).toString());
try{
player.setDataSource(getApplicationContext(), trackUri);
}
catch(Exception e){
Log.e("MUSIC SERVICE", "Error setting data source", e);
}
player.prepareAsync();
}
private void showNotification(){
Intent notIntent = new Intent(this, MyActivity.class);
notIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendInt = PendingIntent.getActivity(this, 0,
notIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification.Builder builder = new Notification.Builder(this);
builder.setContentIntent(pendInt)
.setTicker(name)
.setOngoing(true)
.setContentTitle("Playing")
.setContentText(name);
Notification not = builder.build();
startForeground(NOTIFY_ID, not);
}
#Override
public void onDestroy()
{
stopForeground(true);
}
}
MyActivity.java
public class MyActivity extends Activity {
// ***************************** Attributes Start ******************************************************
private ArrayList<File> myfiles= new ArrayList<File>();
private ListView listView;
private ArrayAdapter<String> adapter ;
private String name="";
private int position;
private AudioService musicSrv;
private Intent playIntent;
private boolean musicBound=false;
// ***************************** Attributes End ******************************************************
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
String toneslist[] ={"Airtel"
,"sherlock_theme"};
listView = (ListView) findViewById(R.id.listView);
adapter = new ArrayAdapter<String>(getApplication(),R.layout.list_item,R.id.list_textview,toneslist);
listView.setAdapter(adapter);
getMp3();
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int pos, long id) {
name =adapter.getItem(pos);
position =pos;
Log.e("MAINACTIVITY (clickListener) pos =",""+position+" name = "+name);
musicSrv.setSong(position);
musicSrv.playSong();
}
});
}
#Override
protected void onStart() {
super.onStart();
if(playIntent==null){
Log.e("MAINACTIVITY pos =",""+position+" name = "+name);
playIntent = new Intent(this, AudioService.class).putExtra("pos",position).putExtra("songlist", myfiles).putExtra("name", name);
bindService(playIntent, audioConnection, Context.BIND_AUTO_CREATE);
startService(playIntent);
}
}
private ServiceConnection audioConnection = new ServiceConnection() {
#Override
public void onServiceConnected(ComponentName name, IBinder service) {
AudioService.AudioBinder binder = (AudioService.AudioBinder)service;
musicSrv = binder.getService();
musicSrv.setList(myfiles);
musicBound = true;
}
#Override
public void onServiceDisconnected(ComponentName name) {
musicBound = false;
}
};
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private void getMp3(){
String s=(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)).toString();
// s="content://media/external/audio/media";
GetFiles(s);
}
private void GetFiles(String path) {
File file = new File(path);
File[] allfiles = file.listFiles();
if (allfiles.length == 0) {
} else {
for (int i = 0; i < allfiles.length; i++)
{
Log.e("FFFFFFFFF", allfiles[i].getName().toString());
myfiles.add(allfiles[i]);
}
}
}
#Override
protected void onPause() {
super.onPause();
}
#Override
protected void onDestroy() {
stopService(playIntent);
musicSrv=null;
super.onDestroy();
}
}
Try with this in your Activity:
#Override
public void onDestroy(){
if (!isChangingConfigurations()) stopService(new Intent (this, YourService.class));
super.onDestroy();
}
#Override
public void onBackPressed(){
if (mediaIsPlaying) moveTaskToBack(true);
else super.onBackPressed();
}

Accessing an activity through a service

I have an Activity and a service.
The activity has a TextView member and a setText() method.
I would like to call that method through the Service, how can I do that?
Here is the code:
Activity:
public class MainActivity extends Activity {
private TextView tv1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.tv1 = (TextView) findViewById(R.id.textView1);
Intent intent = new Intent(this,MyService.class);
startService(intent);
}
// <-- some deleted methods.. -->
public void setText(String st) {
this.tv1.setText(st);
}
}
Service:
public class MyService extends Service {
private Timer timer;
private int counter;
public void onCreate() {
super.onCreate();
this.timer = new Timer();
this.counter = 0;
startService();
}
private void startService() {
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
//MainActivityInstance.setText(MyService.this.counter); somthing like that
MyService.this.counter++;
if(counter == 1000)
timer.cancel();
}
},0,100);
}
#Override
public IBinder onBind(Intent arg0) {
return null;
}
}
You can use an intent in order to send any information (i.e. the counter for TextView member) to the Activity.
public void run() {
//MainActivityInstance.setText(MyService.this.counter); somthing like that
MyService.this.counter++;
Intent intentBroadcast = new Intent("MainActivity");
intentBroadcast.putExtra("counter",MyService.this.counter);
sendBroadcast(intentBroadcast);
if(counter == 1000)
timer.cancel();
}
...then, you will receive your data in the Activity using a Broadcast Receiver
/**
* Declares Broadcast Reciver for recive location from Location Service
*/
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
// Get data from intent
serviceCounter = intent.getIntExtra("counter", 0);
// Change TextView
setText(String.valueOf(counterService));
}
};

Categories

Resources