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

Android Studio emulator is Force Stopping the app when swiped [duplicate]
single tap for more events
How to add file/camera uploading ability to Turbolinks 5 running on android?
what modifications needed to send verification email before creating user in firebase
How to get ascending percentage on ProgressBar connected with CountDownTimer?
How do I exit a fragment and return to my drawer activity using the back button?
AdRequest not resolved, and marked with RED,But the app works fine
How make drawable folder for any phone and tablet size on android?
Text to Speech is not working in the activity (android)
How to broadcast an intent from UIautomator
Cannot filter RecyclerView using Spinner
How to fix Calling a method in the system process without a qualified user this error in the system android application?
can't add a file or application to /system/xbin of andriod
how to check my host server is availability
Can I populate a expandable listview with json data using volley?
arm64-v8a type OS Architecture device for Android device not working

Categories

HOME
embedded
turing-machines
design-patterns
developer-tools
c99
toolbox
error-handling
google-cloud-functions
cq5
telegram-bot
nested-if
hpc
code-coverage
lanczos
siddhi
opengl-es-3.0
filechannel
openbugs
nancy
eip
selectize.js
entitymanager
feathersjs
google-content-api
pyramid
identity-management
symfony-console
dataflow-diagram
short-url
dapper-extensions
jackson-modules
flooding
carrierwave
vex
postback
turfjs
clickjacking
sammy.js
installshield-le
searchkit
lint
wurfl
resolution
attributeerror
tcc
term
hammer.js
android-testing
filehandle
jqchart
otp
janus
rackspace-cloud
bootstrap-tags-input
branch-prediction
flex-monkey
redbeard-ios
jodd
android-wake-lock
kiosk
jparsec
relativelayout
sapi
fiware-monitoring
phonertc
dot.js
adehabitathr
dbaccess
execve
deform
tweenlite
nsmenu
live555
vsx
authlogic
gwt-openlayers
kendo-dataviz
away3d
flex++
actiondispatch
pdfviewer
jdb
azman
koken
fitbounds
hibernateexception
pinch
tournament
quotation-marks
socketserver
svk
drupal-fivestar
wcf-instancing
fault-tolerance
flvplayback
information-management
online-storage
wspbuilder
pnrp

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