Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Is it possible to create a reference to an existing layout file in a specialized layout folder? For example, on the Nexus 7 I want to use a two-column layout when in landscape mode but a single-column phone layout in portrait mode. Can I create a reference to /res/layout/activity_layout.xml in /res/layout-sw600dp-port/ so that I only have to edit one activity_layout.xml file instead of maintaining a copy of it within /res/layout-sw600dp-port/?

How SlidingMenu does it is how it's done. (https://github.com/jfeinstein10/SlidingMenu/tree/master/example/res/layout-large-land)

You aren't going to be able to deduplicate the layout code but if you really really need to there is an include tag, I believe. If you have such need for ui reuse consider fragments.

Adbot
ADBOT LOVES YOU

Doctor w-rw-rw-
Jun 24, 2008

it is posted:

Maybe it's just because I'm trying to learn how to integrate Facebook into Android before becoming fluent in Android, but figuring out exactly HOW Facebook wants you to authenticate is extremely frustrating. This code (called from my MainActivity)

WHY

Called from where in your MainActivity?

Doctor w-rw-rw-
Jun 24, 2008

it is posted:

onCreate

So you're creating another activity before one has had the chance to finish onCreate/onStart/onResume. This might not be a problem but it wouldn't hurt to check your assumptions. I would try creating a test button or menu that triggers the same function on that screen, then see if the same error is produced.

Doctor w-rw-rw-
Jun 24, 2008
Hmm, I can't really say for sure. Perhaps you're missing an argument somewhere. Whatever's happening, it's obviously expecting some data that ain't there.

Doctor w-rw-rw-
Jun 24, 2008

Above Our Own posted:

I'm looking to develop in .NET for android. Is Xamarin's Mono for Android the most feature complete solution? I'm really wanting to spend as little time as possible porting.
There are other solutions for .NET on Android? News to me.

Above Our Own posted:

I'm also doing a little XNA development on the side, and it would be nice to port this over to Android as well. I understand ExEn runs on top of Xamarin's platform, are there other options for porting XNA to android? Again, I really want to avoid having to write platform-specific code as much as possible and I'm willing to pay for that convenience.
If you want some sort of UI framework with the same abstraction across platforms, unless I've forgotten something, Xamarin isn't that. It won't save you from writing platform-specific code, it'll save you from writing Java code. I've never heard of ExEn, then again, I've never writing anything on the CLR. So I guess just use ExEn on top of Mono for Android.

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Is a ContentProvider necessary when I'm just working with internal SQLite databases? I'm learning about them now and am left wondering if implementing one would be overkill; all I want to do is move database queries into a separate thread so the app won't hang. Right now I'm only querying static databases, though I will eventually implement another database that will be populated with user-generated content produced from within the app. I want to handle all of the database-related stuff in a database helper class, but everything I've read about introducing threading into the process points me to implementing a CP.

If ContentProviders are something I need to learn if I'm going to be working with SQLite, then can someone help me understand how to best craft URI's? I've skimmed a few ContentProvider tutorials and still can't wrap my head around how I'm supposed to craft URI's for my various use cases. I'm afraid I'll gently caress up and create a CP that's too limited in scope (or go the other way and set up too many URI's) and that'll force me to go back and rewrite large sections of code.

Skip 'em to start with. If you need to load them asynchronously, there's a loader framework library by CommonsWare for providerless cursors.

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Oh yeah, making the queries and processing the returned results isn't the issue. I was just looking for a simple way to do all of the queries in a separate thread so I don't freeze the app's UI thread. I'll try and do everything in the main thread for now - with luck I'll be able to get away with it.

Use the commonsware library. It's only slightly overkill, not massive overkill like providers.

Doctor w-rw-rw-
Jun 24, 2008
The swapCursor(null) advice is correct to my recollection, but are you sure you're supposed to close it?

http://stackoverflow.com/questions/8864813/if-and-when-to-close-the-database-when-using-commonsware-loaderex-sqlitecursorlo?rq=1

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Is this something a fragment transaction could solve? I use it right now to bring up Fragment B in one-column mode, but as I write out this post I'm starting to think that I should dynamically load up fragments with FragmentTransactions in lieu of setting up my fragments statically in the activity's layout file...

Yeah, pretty much. Load them up in FragmentTransactions. Also, remember that fragment state on the backstack is thrown away completely on configuration changes (such as orientation), though the backstack isn't destroyed. Just the state.

Doctor w-rw-rw-
Jun 24, 2008
It's been a while so the stuff is fading from memory. I do remember a few things:
  • LinearLayout is a ViewGroup. ViewGroup is abstract. I think you're OK.
  • Look at https://github.com/jfeinstein10/SlidingMenu <--the example there i think shows a decent way to show a double-column layout on tablets.
  • Fragments let you save and restore their state from bundles. I'm hazy on this since I haven't touched android in a couple of months.
  • Don't nest fragments.

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

What's the best way to close a foreground activity and pass info back to the parent activity after rotating the screen? My app displays two columns in landscape mode and one column in portrait mode. When the device is in portrait mode, tapping on a listView item in Activity A starts up Activity B and displays additional information about that entry.

I ultimately want to pass Activity B's current entry ID back to Activity A when the device is rotated into landscape mode while Activity B is active. Right now I've got the following set up in Activity B's onStop():

Java code:
@Override
protected void onStop()
{
    super.onStop();
    Log.i("ActivityEntryDetails", "onStop - " + entryID);
    Intent i = new Intent(this, ActivityStartScreen.class);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    i.putExtra("entryID", entryID);
    startActivity(i);
    finish();
}
While this does what I want, I feel as though I'm doing something wrong; after rotating into landscape mode a copy of Activity A disappears into the background over top of the actual Activity A using the same animation as though I'd tapped the Back button to go to the previous activity (that's a lovely description of the issue but it's hard to put into words). What's a better way to do this?

Use startActivityForResult/onActivityResult.
stuff your data into an intent. Parcelable is better than Serializable when possible (Serializable uses reflection, and is slow; Parcelable requires you to implement a builder/parceler

Protip: rather than calling startActivity or startActivityForResult, I usually make a class method that resembles: static void start(Activity activity, String arg1, SomeObject arg2) - or startForResult to indicate that it returns a result. It's much easier to find where an activity is launched from when all you have to do is find where a function is called from.

Doctor w-rw-rw-
Jun 24, 2008
Don't do activity life cycle stuff in onCreate IMO. I don't really understand what you want to do. You want orientation changes to back out of an activity? If that happened to me I would consider it a bug. What if someone is in a bumpy train ride and the orientation changes? What if you later decide to launch that activity from some other place where it doesn't make sense to close it?

Doctor w-rw-rw-
Jun 24, 2008
I think ViewPagerIndicator also has the same control. If so then use that library, as the same guy behind ActionBarSherlock is behind VPI, so you're assured some level of quality.

Doctor w-rw-rw-
Jun 24, 2008
I have done both iOS and Android dev professionally for three years. PM me with some details and I'll make some time to get back to you about potential pitfalls, things to use, and stuff to keep an eye on.

Doctor w-rw-rw-
Jun 24, 2008
Holy loving poo poo.

Volley.

Every single pitfall that the presenter pointed was something I encountered in making network requests. Every single solution and diagram was something I had drawn up as a solution but was never given time to implement properly.every feature addressed a deficiency I needed.

And it's backwards-compatible to older versions of android. Wow. Great!

Doctor w-rw-rw-
Jun 24, 2008
They said that they compared it to a bunch of other libs out there and that itwvperformance trounced the others'.

Doctor w-rw-rw-
Jun 24, 2008

jkyuusai posted:

The "what the hell is Android going to do about new Java features since Oracle hates you" question came up during the keynote

Hey now, I didn't phrase it nearly so harshly at the keynote. >:/ though I agree, it was totally dodged. Sad. I hope that the questions get them to think harder about the problem, at least. That was my intention, anyway.

Doctor w-rw-rw-
Jun 24, 2008

Sereri posted:

Wait, that was you?

Yes.

Doctor w-rw-rw-
Jun 24, 2008

QuarkJets posted:

Perhaps Google will provide expanded Python support and give Oracle the finger

I doubt it and would hate for this to happen. I think the right move forward is to build a LLVM-based solution. Not only could they build first-class support* for writing Android apps on top of their already-present NDK platform (which already supports LLVM iirc), but if they could tie PNaCl in somehow, they could make the ChromeOS story instantly very compelling by providing a porting path between Android and ChromeOS. Python and other languages could simply sit atop LLVM and do their thing.

* As in, not just a bridge

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

I've just hooked up a spinner in the Action Bar to a CursorAdapter (I'm cheating right now and am using a SimpleCursorAdapter, but will replace it with something custom). When an item in the spinner is selected, onNavigationItemSelected(int position, long id) is called. I know position is the tapped item's location in the list of items, but what is id? Is it whatever I returned as the _id column when I selected rows from the database?

it's the primary key by which the item is identified. I just had an auto_increment field, I think. I'm not sure anymore what it's used for, but the most common error I've had with non-unique IDs and UI controls is the wrong UI control responding because it got called earlier than the one you intended to respond, because they have identical IDs.

If you want something custom, try an ArrayAdapter subclass?

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

That's what I figured. In my case it's the row's _id column, which is perfect since I need to reference that when a particular spinner item is tapped.

As for the custom class, I'm using a CursorAdapter because the items I'm pulling are stored in a database. The user can create, update, and delete these items at will, so I can't work with static lists.

ArrayAdapters don't have to be static lists. In fact, the only way I've ever used them is as a destination for API-backed calls. No overhead of reading/writing to a database, just memory. It also frees you from being inseparably married to your SQLite code for any kind of data manipulation.

That said, do what is simplest for what you need. POJO-backed lists is not necessarily that.

Doctor w-rw-rw-
Jun 24, 2008

more like dICK posted:

What's the general pattern for an android app that needs a long running socket? I'd use HTTP, but the app needs to respond to arbitrary events from the server while the user is interacting with it. This looks like something that should be done with a service, but I haven't used those in the past.

SPDY with server push and Square's Okhttp library?

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Hell yeah, this was the missing piece of the puzzle! With them I finally able to figure out a way to helpfully block user interaction (via a dialogfragment) while database operations (or anything else long-running for that matter) occur on a separate thread. Thanks to you I'm almost ready for launch! :toot:

Don't forget intent services

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

What's the difference between using a Thread versus using an IntentService to do something like, say, modify database schema?
IntentServices only run when needed and fit in better with the android lifecycle.. They're not necessary the best solution but they are an easy one.

Doctor w-rw-rw-
Jun 24, 2008

Sereri posted:

But isn't it just dropping the ABS, including the library and removing all the Sherlock prefixes?

It should be, but different code is different code and if you stick by "don't fix what ain't broke" (and conveniently ignore that Android itself is often broken), just stick with what you were already using.

I haven't taken a look at Android in a while, but one useful thing I could imagine remaining useful is VPI (ViewPagerIndicator).

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Do any of you guys have any experience with the Play Store's third-party translation services? I translated the UI of my Japanese dictionary app into Japanese but want someone native to proof-read it. I'm feeling bad asking friends to proof my stuff for free, so I'm considering shelling out a bit of cash up front to get a bona fide translation in place before launch.

PM tarepanda. He should be fluent and know a thing or two about apps, I think.

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Is it strange to put in an offline ad banner?

My app is free to download with IAP to disable ads. In earlier releases, users could use my app on their offline device as though they'd purchased the no-ads IAP. I didn't think that was fair to paying users (or me), so I put in a banner that prompts people to buy the IAP in instances when the AdMob server couldn't be contacted.

At least one person responded negatively to it, though, so now I'm wondering if I'm going to shoot myself in the foot in the long-term.

Mobile connectivity is generally poo poo. Sacrificing usability to do right by your paying users in this way won't net you any more money, and it destroys your freemium funnel. That's two pretty lovely alternatives. Is there a third?

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Honest question, am I sacrificing usability by placing a "tap here to get rids of ads" view that's the same size as an ad the user would see if they were online? The ad's not an interstitial, and it's only a 50dp tall TextView located at the bottom of the screen in the same container that an ad would appear.

And what do you mean by, "it destroys your freemium funnel"? Just to clarify, my app is a Japanese-English dictionary - there's nothing freemium in my app. All functionality is enabled regardless of whether the user has purchased the upgrade to remove ads. It seemed to be the easiest way to get people to use the app while still leaving open a small window for people to support my work.

As for a third alternative, there's not a whole lot I have to work with. Like I said earlier, all functionality is available to users the moment they download the app. I could just charge for the app, but it seems pretty common knowledge that that monetization model is more successful on iOS than on the Android side of things.

This is my first Android app rodeo, so I'm honestly not sure what works or doesn't work when it comes to monetizing apps.

I misread. I thought your app disables itself if the ad doesn't fill. Yeah, just make it less convenient for free users vs paid users. People determined to not spend money will do many things to not pay.

Doctor w-rw-rw- fucked around with this message at 01:31 on Sep 3, 2013

Doctor w-rw-rw-
Jun 24, 2008

Ulysses S. Grant posted:



Boy, isn't it great that there's gonna be another new Android version? 4.3's been out for like a whole month or something!

Psh. You effectively have a 2.3 target and a 4.0+ target. That's a piece of cake next to the Eclair-Gingerbread-Honeycomb compatibility I had to do back in my day, when we had to walk uphill both ways (granted, in SF, you still generally have to literally walk uphill both ways). Gone are the days of lovely incomplete SQLite support, a missing String.isEmpty implementation, and poisoned HttpURLConnection connection pools.

*shakes cane*

Doctor w-rw-rw-
Jun 24, 2008

Salvador Dalvik posted:

Besides, Google's pretty much given up on core OS changes, it's all Play services and support library additions from here on out.

Yay, I guess?

Well, they moved core OS apps from the OS to the Play Store, more like. Makes sense that a lot of that stuff doesn't need to be carrier-certified and would benefit from a more iterative update cycle. I think having to live on their own platform will help them make it more livable for all of their developers.

Now if only Android had an animation framework that didn't totally blow.

Doctor w-rw-rw-
Jun 24, 2008
Facebook's been using and improving Buck: http://facebook.github.io/buck/setup/quickstart.html

Which can generate IntelliJ projects and is apparently working out really well so far. Just putting that out there.

Doctor w-rw-rw-
Jun 24, 2008

Jarl posted:

When would you use the fragment backstack instead of the regular activty backstack? What is the Android way?

I wouldn't use the fragment backstack because it throws away fragment state.

Doctor w-rw-rw-
Jun 24, 2008

Jarl posted:

But fragment has onSaveInstanceState just like activity. Besides making it possible to save the state, even if the fragment is killed while another activity is active, this, to me, also implies that a fragment on the fragment-backstack is retained in memory until killing it becomes necessary.

Am I misunderstanding this?

It isn't called in all situations. It's been a couple of years since I wrestled with this, but this might have been because of view pagers or fragment pager adapters not calling the state-saving methods - I don't specifically recall. Or perhaps some interaction with launching activities. In any case, I found it unreliable and broken.

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

Is there a way to read a single file from a ZIP file store in the /assets/ directory? I want to use ZipFile.getEntry() to dynamically grab a specific file, but I can't figure out how to get the ZIP file in a position to do that. A lot of guides and SO articles related to this use ZipInputStream to read the contents of a given ZIP file, but that involves iterating over every single compressed file to find the one you want. The ZIP file I'm working with has almost 6700 SVG files in it, that's not feasible.

EDIT: Nevermind, I'm just going to dump the SVG files into the main OBB file and read them using Google's APKExpansionSupport library.

Iterating over 6700 small entries in a small contiguous range of bytes is not necessarily expensive, especially not if it's done once at startup and you cache the zip entries.

In any case, assets are actually already accessed directly from within the APK, which is a compressed zip file, so you really don't gain anything by accessing a file-within-a-zip-within-a-zip. What is your rationale for zipping it up vs, say, putting it in a subdirectory of the assets folder vs. packaging it separately?

Doctor w-rw-rw-
Jun 24, 2008

Jarl posted:

I have a stack A_1->A_2->A_3->B (A_1, A_2 and A_3 are all instances of the same activity A) and I want to pop back to the A_1 (root activity you will) without it being restarted it (i.e. onCreate being run), and hence with the rest of the stack finishing.

Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK doesn't work, since it restarts the activity and Intent.FLAG_ACTIVITY_CLEAR_TOP doesn't work either since it also restarts the activity.

I just want it to be like if the user had used the back button until they were back at A_1.

Start the activities with an intent that includes a counter, and finish with a result code that signals the chain of activities should finish themselves until they hit the original counter of 0? Or just destructively do it as you start activities by finishing the predecessor at the same time, if I understand correctly.

Doctor w-rw-rw-
Jun 24, 2008

Unexpected posted:

I have a newbie question (sorry). If I wanted to write a simple app that would work on both Android and iOS, do I create it on one platform (e.g. XCode on Mac) and then "rewrite" it for Java (as an example) or is there an application that would handle conversion "automatically". I know literally nothing about Android (and Java), so apologies if what I'm asking is retarded.

Xamarin is the only environment with a realistic approach to writing native apps for each platform using the same language (without resorting to C/C++). The other environments typically offer you variations on a HTML/JS/CSS kind of environment, but it'll generally be very difficult even for moderately experienced developers to make a quality app that feels native on both.

Having developed extensively for both Android and iOS. I can't recommend strongly enough that you should _not_ start on Android for a first platform if the choice is between Android and iOS. iOS is easier to get started on, more profitable, and more fun. Completely worth the price of admission.

Doctor w-rw-rw-
Jun 24, 2008

Karthe posted:

I finished migrating my project to Gradle, but I compiled a release APK just now and noticed a couple of problems. The APK is 300% larger than when I was compiling it with ANT, and the Play Store now reports that this new APK includes localizations for every language, not just the two I actually have localizations for.

What did I do wrong?

Try unzipping the APK and running du -h on the directory to compare file sizes for a better idea of the difference.

Doctor w-rw-rw-
Jun 24, 2008

mod sassinator posted:

Wow, great OP in this thread. I'm just getting started in Android development and found the info really useful.

One thing I'm curious about, is there any pattern for MVC/MVVM/etc. style application development in Android? I've done stuff in the windows and web worlds where there's nice databinding support so you can build a simple model and bind its values directly to UI elements (i.e. updating an edit box changes the value of a model property automatically). From looking at the Android docs and searching around a bit it doesn't seem like there's anything native in the Android SDK for it. Is there any mature or frequently used libraries for MVC style development in Android?

Friend of mine wrote this: https://github.com/depoll/bindroid

Doctor w-rw-rw-
Jun 24, 2008

mod sassinator posted:

Awesome--I'm really impressed with Square's libraries. Those guys really seem to be on top of Android development.

I should hope so. Bob Lee, their CTO, previously led core library development on Android at Google.

Adbot
ADBOT LOVES YOU

Doctor w-rw-rw-
Jun 24, 2008

Tunga posted:

Looks like Color.toString() doesn't have defined behaviour so probably avoid just putting the object in the log output.

Other than that, you didn't really describe what problem you are actually having. What behaviour are you seeing?
What are you smoking? There's no object being printed here. The problem is clear - the color isn't being set.

Elvis:
-2^24 is 0xFF000000. In ARGB this means a totally opaque black. This means that red, green, and blue are consistently zero. Take a look at your constructor and you'll see you never actually set the instance variables.

I assume you're new to programming, if not in general, then at least to Java. You would do well (generally) to recognize certain powers of two, and (specifically) learn how to use Java's debugger. Those will go a long way in helping you solve your problems in the future. Luckily, Java is one of the easiest languages to use a debugger with IMO, its other shortcomings aside.

Doctor w-rw-rw- fucked around with this message at 08:55 on Mar 16, 2014

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply