Creating a messenger in Android - java

I'm (sort of) new to android development and I'd like to create an android messenger app based on the PircBot library.
There're several constraints I am aware of right now:
must use IRC, probably can't change this now since it's already in the requirement
IRC service needs to run in its own process so it doesn't interfere with UI while listening to IRC messages and it should receive messages in the background and send notification without having UI showing
I'm using different activities for different screens so all activities will need to use the service (logged in, joined channel, send/recieve message) and different activities should be notified based on the current state of the connection.
I've tried to bind the service from my activity but binder seems to only work with services in the same process. (I'm not sure on this one, search didn't return anything useful)
What's the preferred way to structure my project so that all the constraints can be satisfied? Also what other problems might I ran into?
Sorry for the bad english

IRC service needs to run in its own process so it doesn't interfere with UI while listening to IRC
I don't see any reason why the IRC service would need to run in its own process. A service, is, by definition, an element that does not interact with the user, as stated in the docs:
A Service is an application component representing either an
application's desire to perform a longer-running operation while not
interacting with the user or to supply functionality for other
applications to use.
And, as you said, by making this service run in its own process, it becomes impossible to bind to it (indeed, you need to do IPC communication at that point).
I'm using different activities for different screens so all activities
will need to use the service (logged in, joined channel, send/recieve
message) and different activities should be notified based on the
current state of the connection.
To satisfy this requirement, you can simply use the LocalBroadcastManager to share information from the service to all the activities. Your activities could have BroadcastReceivers for the events they wish to hear (connectionStateChange, MessageReceived, etc.), and would act accordingly.
Finally, because reading other people's code is always a good idea, check out these two similar projects, brought to you by your friendly search engine:
Android's SMS/MMS app
A simple IM app for Android

Related

how to send post data continuosly to web and mobile

I am going to develop uber-like application.Here I have to send latitude and longitude to web and mobile devices continuously with my service,What I have do to get this.
Can anyone please give some idea.
You should start by designing how the application is to be used, seen from all the different users perspectives.
For instance is this a web app, or a native app, or both?
Then from that knowledge, you need to define a communication protocol.
You should be able to determine if the client will be polling for data, or if you need to push it from the server onto the clients.
This also goes for the data that travels the other way.
From here you choose a language for programming, and then start doing some proof of concept tests.
The choice will depend on the chosen underlying technologies
(web / native / os / available libraries)
After some test work you may have something that works, then you need to review or add security to the communication, cause we do not want everyone collecting location data from everyone that has the app installed.
Then run beta trials and eliminate the worst bugs, and then release the app.
You'll want some sort of asynchronous task which can get new data from your server and refresh the mobile and web content to reflect the content of the server. You'll also want to notify the server whenever you make local changes to content and want to reflect those changes. Android provides the SyncAdapter pattern as a way to easily solve this pattern. You'll need to register user accounts, and then Android will perform lots of magic for you, and allow you to automatically sync. Here's a good tutorial: http://www.c99.org/2010/01/23/writing-an-android-sync-provider-part-1/

How to create immediate Notification System in website

I am implementing a small social networking website, and I am trying to implement notifications.
Notifications have the following requirements
All users will receive notifications whenever users they follow do
certain events (like a post, create a post,leave a comment, etc...
When a set of notifications for a user is unread, just like on facebook, the user will
continue to see a read notification icon on their navbar.
Problem : I am taking an example to describe my problem for better understanding for everyone.
Suppose there are two users A and B. A & B are friends and A post something, suddenly B like the post of A then A should have to receive the notification immediately.
So how can i achieve this immediately receiving of notification process?
Should i send a call to server on each millisecond to check whether there is any unread notification is available for A user ? In this case thousand millions of call creating for multiple user. It is feasible solution ?
(I think it create unnecessary load on my website. As i think facebook and stackoverflow do not use this way).
Provide me a suitable solution just like fb and other webiste using.
Technology Using in my project: Java and MYSQL
You should use JavaScript (client side) along with Java - MySql (Server side), and more specifically Ajax. You will need some time to understand the concept and the usage but it does exactly what you want.
To give more details, what you need is to create a partial view where the notifications will appear, and update this partial view async (with AJAX).
Dont reinvent the wheel.
Use ajax call to server at each interval and check your server and update nav acc.
1.So how can i achieve this immediately receiving of notification process?
2) Should i send a call to server on each millisecond to check whether there is any unread notification is available for A user ?
Your above both questions answers solve through GWTEventService implementation.
Through it you can write code that will avoid client to server round trip.
GWTEventService is an event-based client-server communication framework. It uses GWT-RPC and the Comet / server-push technique. The client side offers a high-level API with opportunities to register listeners to the server like to a GUI component. Events can be added to a context/domain on the server side and the listeners on the client side get informed about the incoming events. The server side is completely independent of the client implementation and is highly configurable. Domains can be defined to decide which events are important for the different contexts.
Refer link: https://code.google.com/p/gwteventservice/

Android: How to trigger screen UI events (e.g incoming call screen) by a long running background service?

I'm quite new to android. I'm building an application that uses the android smack library to communicate with my XMPP server. I am able to send and receive messages perfectly however what I want is to run this ENTIRE sending and receiving messages code to a long term running process in the background and on receiving a certain message I want to launch a screen (something similar to the incoming call screen of android) no matter what the user is doing on his smartphone i.e. when the activity running the messaging service is not open (in a similar way when you get an incoming call from a viber contact and you get faced with the screen even though you obviously dont have the viber application open).
Any ideas on how exactly to do this ?
I have a few ideas in mind after research but dont quite seem to get the correct way and glue all peaces together.
Thanks in advance
you can use intentService to communicate with mainThread
here is a basic examples of intentservice and service
http://mobile.tutsplus.com/tutorials/android/android-fundamentals-intentservice-basics/
service example
http://www.vogella.com/articles/AndroidServices/article.html
here is an official document
http://developer.android.com/reference/android/app/IntentService.html

Send and forget library for Android

When I program apps, usually I need to do something that can fail (the most typical is send something to a server), many times the "send and forget" would be the best option (or a send and forget with a expiration date).
I know it is a very generic problem but is there some library that facilitates the save and retry process?
As #CodeChimp says, you'll probably need to roll your own.
That said, the usual pattern for Android is to write a Service that handles saving/retry.
Your app would pass the data to the service (send and forget), and the service would then take care of trying to send in the background.
The big question for this sort of thing is always how to handle failure. What happens after the save fails some number of times? You're on your own here too. Depending on your situation, you could notify the user (via a Notification), save the error in the app's database, and notify the user in the app's UI, etc...

Android --- Connecting activities and services

I have this basic design in mind:
A main activity will offer a choice of sub activities and also create a Bluetooth service.
The Bluetooth service will reads and buffer live data from a Bluetooth connected device. Enough data , at a fast enough rate (100 to 1000 sps ) so that I don't think it is realistic to use Intents or broadcasting
The sub activities will simply be displaying the same received data but in different way.
Each sub activities will also the user to interact with the data in a different way.
I really prefer that the Bluetooth service is agnostic of the Activity/View onto which the data gets presented.
I'd be willing to 'register' a bunch a 'destination' (which would really be activities) to which 'cooked' data would be sent to. I didn't quite get how to 'register' anything from starting an activity.
How do I pass, for example, a reference to my service to each of those activities? Or it might be the other way around; how do I register each activity to the running service.
Having a C/C++ background, I realize this might not be a good approach in Java.
Thank you.
Ideally this not NOT the best way to approach it. Specifically android is a system that bases its services on passing information via intents from activity to activity, activity to service, service to service.
The way I would approach this would involving having an app on the phone that would be communicating with a service. Specifically the app would receive the data from the service. However; in order to allow the activity to listen to it, you could have the service broadcast a message saying there is new information, and have this activity intercept it. When the service is building this message, you could have information passed via an intent (extra) to the activity. The activity would have a Broadcast Listener inside of it that specifically updates information relative to that service inside of that activity.
And perhaps to keep information from being lost, throw messages into a stack and read it accordingly until its empty (This is assuming you get ton of information)
These links should help
Broadcast Reciever
http://thinkandroid.wordpress.com/2010/02/02/custom-intents-and-broadcasting-with-receivers/
Services
http://developer.android.com/reference/android/app/Service.html
http://marakana.com/forums/android/examples/60.html

Categories

Resources