android


How to Start one Activity and two service on notification click


When user click on notification I want to start an Activity and two Intent Service.
Is it possible to do ? If yes Please can any one give me the idea to do this ?
Suppose I have no control on Activity. The Activity belongs to third party app.
Please don't tell me that start intent service from your Activity . I know this.
Follow the steps Hope this helps you
1) Create a BroadCastReceiver
public class MyBroadcastReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
// Start Activity
// Start Services
}
}
2) Just Fire Broadcast on notification click.
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(context, MyBroadcastReceiver.class);
PendingIntent contentIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
Notification notification = new Notification(icon, ticker, when);
notification.setLatestEventInfo(mSmartAndroidActivity, title, message, contentIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
Use PendingIntent.getBroadcast instead of PendingIntent.getActivity
3) In BroadcastReceiver's onReceive() method
-> call your third party activity
-> Start services
The answer given by Biraj will also do the job.
But for that You have to declare the BroadcastReceiver in your manifest file as well as all activity and services which you are starting from BroadcastReceiver.
So I have not choosen the above way.
How I have implemented ?
I have started an Intent service from where I am starting activity and making a synchronous request to server . By this way I don't have to declare a BroadcastReceiver in my maniest file.
I believe in writing less code so I have chosen the above Intent Service way

Related Links

ListView and ReferenceHolder
Android: NoClassDefFound
How do I add a ViewPager as the top item in my ListView
Adwhril with Millinial media,ZestAdz and InMobi is giving errors
how to adjust the width of Android TextView dynamically
Despite changes in code my Android app isn't reinstalling onto my AVD in Eclipse?
Adding EditText to LinearLayout programatically in android
AndEngine Examples not working
Android - Opening Default Music Library Properly
MediaStore not finding all files
Is WTP plugin needed for consuming web services in Android?
How to increase width of particular EditText in Table Raw (Table layout)
Android - The app is crashing when taking photo with custom camera app
Getting latitude and longitude by GPS
How to reduce the check box size in android?
The field is never read locally (catch-22)

Categories

HOME
algorithm
facebook-oauth
paraview
delphi-7
prism
powerpoint
jsf-2.2
onclick
jquery-ui
tvos
odoo-8
extjs4.2
fabric.io
java.util.logging
redis-sentinel
php-5.6
libc
dynatrace
magnetic-cards
azure-powershell
atlassian-stash
delphi-xe5
asp.net-core-webapi
qliksense
scriptella
definitelytyped
surveymonkey
asymptotic-complexity
custom-controls
powershell-ise
mockjax
record
cognos-bi
sql-server-2000
jmockit
biztalk-rule-engine
reactjs.net
carriage-return
jwplayer6
engine.io
apiary.io
google-knowledge-graph
sim-card
apriori
android-softkeyboard
naming
print-css
logback-groovy
congestion-control
apache-directory
getchar
httrack
serde
dotnet-httpclient
video-conferencing
appdomain
slackware
redbeard-ios
qtplugin
xdoclet
deep
lz77
html-to-pdf
halcon
tfs-workitem
dulwich
pyobjc
canvg
git-ftp
rrule
showdialog
strawberry-perl
raygun
trdion2011
tinyxml
drupal-nodes
openargs
inputmismatchexception
rolify
beaker-testing
workitem
jquery-blockui
uimanageddocument
boost-msm
ilasm
cgimage
htdocs
webdev.webserver
massive
xui
luajava
ruby-1.8
easyb
sifr
cfwindow
murmurhash
django-piston
build-environment
glui
business-model
ifilter
change-management

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App