[android-developers] Re: Is app's first run?

2010-03-18 Thread Mark Wyszomierski
Yeah that works perfectly, in my situation I'm working on an existing
project that is already in the wild, so I can't rely on a value in the
preferences file to check for this though. That would be the best
solution I think.

To get around this, I can do something like the following (going off
your original solution):

  File file = new File("/data/data/com.foo.bar/shared_prefs/
com.foo.bar_preferences.xml");
  if (file.exists()) {
...
  }

that is one big hard-coded string, but the existence of this file
seems to work ok. I guess it's alright?

Thanks


On Mar 18, 12:47 pm, Mark Murphy  wrote:
> Mark Wyszomierski wrote:
> > Yeah that definition is perfect, having a little trouble implementing
> > it though.
>
> > I'm just trying to use:
>
> >   File file = getFilesDir();
>
> > this points to:
>
> >   /data/data/com.foo.bar/files
>
> > which is empty though, nothing gets written there during my app's
> > lifetime. My app's directory structure looks like this:
>
> >   com/foo.bar
> >     /cache
> >     /databases
> >        webviewstuff.db
> >     /files
> >     /lib
> >     /shared_prefs
> >        com.foo.bar_preferences.xml
>
> > should I be seeing databases/preferences? Or am I supposed to be
> > looking for the existence of /shared_prefs/
> > com.foo.bar_preferences.xml. If so, is there a proper way to resolve
> > that path other than kind of hard-coding it into my app?
>
> If you have shared preferences, then you can do this:
>
> Step #1: Get your shared preferences (hopefully
> PreferenceManager.getDefaultSharedPreferences())
>
> Step #2: Look for the "hey! I've been run before" preference
>
> Step #2a: If that preference is not found, it's your first run, so set
> that preference (and commit() the change) and do your first-run logic
>
> Step #2b: If that preference is found, you've been run before,
> so...ummm...carry on, or whatever
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android Training...At Your Office:http://commonsware.com/training

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.


Re: [android-developers] Re: Is app's first run?

2010-03-18 Thread Mark Murphy
Mark Wyszomierski wrote:
> Yeah that definition is perfect, having a little trouble implementing
> it though.
> 
> I'm just trying to use:
> 
>   File file = getFilesDir();
> 
> this points to:
> 
>   /data/data/com.foo.bar/files
> 
> which is empty though, nothing gets written there during my app's
> lifetime. My app's directory structure looks like this:
> 
>   com/foo.bar
> /cache
> /databases
>webviewstuff.db
> /files
> /lib
> /shared_prefs
>com.foo.bar_preferences.xml
> 
> should I be seeing databases/preferences? Or am I supposed to be
> looking for the existence of /shared_prefs/
> com.foo.bar_preferences.xml. If so, is there a proper way to resolve
> that path other than kind of hard-coding it into my app?

If you have shared preferences, then you can do this:

Step #1: Get your shared preferences (hopefully
PreferenceManager.getDefaultSharedPreferences())

Step #2: Look for the "hey! I've been run before" preference

Step #2a: If that preference is not found, it's your first run, so set
that preference (and commit() the change) and do your first-run logic

Step #2b: If that preference is found, you've been run before,
so...ummm...carry on, or whatever

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android Training...At Your Office: http://commonsware.com/training

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.


[android-developers] Re: Is app's first run?

2010-03-18 Thread Mark Wyszomierski
Yeah that definition is perfect, having a little trouble implementing
it though.

I'm just trying to use:

  File file = getFilesDir();

this points to:

  /data/data/com.foo.bar/files

which is empty though, nothing gets written there during my app's
lifetime. My app's directory structure looks like this:

  com/foo.bar
/cache
/databases
   webviewstuff.db
/files
/lib
/shared_prefs
   com.foo.bar_preferences.xml

should I be seeing databases/preferences? Or am I supposed to be
looking for the existence of /shared_prefs/
com.foo.bar_preferences.xml. If so, is there a proper way to resolve
that path other than kind of hard-coding it into my app?

Thank you

On Mar 18, 11:50 am, Mark Murphy  wrote:
> Mark Wyszomierski wrote:
> >>> Otherwise, checking for files/databases/preferences is pretty typical 
> >>> AFAIK.
>
> > This sounds like my best bet - so you're saying at app startup, I can
> > check if files/databases/preferences exists - if it does, this is not
> > my first run, if it is missing, then it's my first run?
>
> For a sufficiently-generous definition of "first run", yes.
>
> You will not be able to distinguish between install and
> install-uninstall-reinstall this way. Hopefully, that distinction does
> not matter.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android App Developer Training:http://commonsware.com/training

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

To unsubscribe from this group, send email to 
android-developers+unsubscribegooglegroups.com or reply to this email with the 
words "REMOVE ME" as the subject.


Re: [android-developers] Re: Is app's first run?

2010-03-18 Thread Mark Murphy
Mark Wyszomierski wrote:
>>> Otherwise, checking for files/databases/preferences is pretty typical AFAIK.
> 
> This sounds like my best bet - so you're saying at app startup, I can
> check if files/databases/preferences exists - if it does, this is not
> my first run, if it is missing, then it's my first run?

For a sufficiently-generous definition of "first run", yes.

You will not be able to distinguish between install and
install-uninstall-reinstall this way. Hopefully, that distinction does
not matter.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Training: http://commonsware.com/training

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Is app's first run?

2010-03-18 Thread Mark Wyszomierski
>> Otherwise, checking for files/databases/preferences is pretty typical AFAIK.

This sounds like my best bet - so you're saying at app startup, I can
check if files/databases/preferences exists - if it does, this is not
my first run, if it is missing, then it's my first run?

Thanks

On Mar 18, 11:41 am, Mark Murphy  wrote:
> Mark Wyszomierski wrote:
> > Is there any way to tell whether an application is being run for the
> > first time, other than checking if there are any left over
> > preferences / files from a previous run?
>
> While your app can't receive a broadcast Intent saying it was installed,
> I think you can receive one saying you were updated, if that helps.
>
> Otherwise, checking for files/databases/preferences is pretty typical AFAIK.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Warescription: Three Android Books, Plus Updates, One Low Price!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en