android


Calling getOwnerActivity() method always return null


I have created a simple custom dialog class. In further code I want to run new Intent:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);
But the problem is whenever I call to change into that Intent I always get null in getOwnerActivity() - how to properly call that method?
public class AddToQueueDialog extends Dialog implements View.OnClickListener {
Activity mActivity;
private final String android_id = Settings.Secure.getString(getContext().getContentResolver(),
Settings.Secure.ANDROID_ID);
public Activity getmActivity() {
return mActivity;
}
public void setmActivity(Activity mActivity) {
this.mActivity = mActivity;
}
public AddToQueueDialog(Context context, WashLocation washLocation) {
super(context);
setWashLocation(washLocation);
setmActivity(getOwnerActivity());
}
If you will check the source code and the activity it returns is set only in setOwnerActivity(Activity activity) which is not called anywhere. So if you want getOwnerActivity() to return value different than null, you have to change your constructor like following
public AddToQueueDialog(Context context, WashLocation washLocation) {
super(context);
if (context instanceof Activity) {
setOwnerActivity((Activity) context);
}
setWashLocation(washLocation);
setmActivity(getOwnerActivity());
}
You cant call the getOwnerActivity() in Oncreate
If you try to get owner from the constructor, Android hasn't hooked it yet, so you have no owner yet.
try this instead
public void onAttachedToWindow() {
super.onAttachedToWindow();
// getOwnerActivity() should be defined here if called via showDialog(), so do the related init here
Activity owner = getOwnerActivity();
if (owner != null) {
// owner activity defined here
}
}
context is the owning Activity. Your constructor is called with context. This is the owning Activity.

Related Links

Android API Level requirement
Android - BaseAdapter - XML, ListView, Button
ANDROID Preference Activity not setting default value
How can I suppress the USB permissions dialog?
How to connect internal SQLite database in my Android Application? [closed]
Google Calendar Api buid
How to change the audio track of a video on the fly using ffmpeg in c++?
Is it possible to buil a UI application like WebOS on Android
Can no longer launch apps after upgrding to android sdk tools 20/platform sdk tools 12
forget password is send to email in android
how to Draw Travelling Path between Two GeoPoint in Google Map in android
how detect device is chatting with another Android device?
Data out of sync between a custom CursorLoader and a CursorAdapter backing a ListView
Eclipse wont recognize Android support library revision 9
ARToolkit - call to OpenGL ES API with no current context
how to create android UI so that it does not change with screen resolution?

Categories

HOME
phantom-dsl
phpmyadmin
jax-rs
object
powerpoint
zend-framework
sublimetext
access
alsa
google-cloud-datalab
automatic-ref-counting
renjin
atlassian
scrolltop
coin3d
modbus-tcp
smartclient
sse
oledb
database-connection
spring-async
object-storage
windows-server-2003
onload
delimiter
dst
zend-debugger
deltaspike
biztalk-rule-engine
engine.io
wurfl
android-augmented-reality
verifiable-c
loading
mongoose-schema
dcmtk
android-softkeyboard
softmax
print-css
claims
lpsolve
phpdbg
plan-9
double-click
lightning
magic-draw
lsyncd
autosar
vorpal.js
avspeechsynthesizer
cassia
turbo-prolog
uiactionsheet
grass
qbxml
asyncdisplaykit
libvlc
sapi
r-package
jdi
poppler
snoop
typeconverter
uvc
entity-framework-4.3
rrule
viewer
cuba
malformedurlexception
embedded-fonts
code-duplication
asdf
node-blade
qtconcurrent
uimanageddocument
boost-signals
lambdaj
appjs
django-paypal
collectionviewsource
objective-j
squishit
soappy
ifilter
commercial-application
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