Android’s AsyncTask sucks

12 November, 2011 · By zmbq · Read More · Comment(1)

    I’m dabbling with Android development. Although I’m definitely getting to old to learn another UI platform (after Windows API, Win32, Visual BASIC, WinForms, WPF and, God have mercy on us all – Motif), but a man’s gotta do what a man’s gotta do.

    As in any other UI platform (except VB 6), you can’t perform lengthy operations from the  UI thread because the UI will freeze (except for VB 6, that doesn’t really like threads, or responsive UIs…). The Google people created something called an AsyncTask. When you want to perform a lengthy operation, you fire up an AsyncTask from your UI thread, and all the threading details are taken care for you. You implement a doInBackground method that contains the background processing, and a onPostProcess method that will run in the UI thread after doInBackground is done. Very easy and rather elegant.

    Unfortunately, it doesn’t work well in real life. You see, in Android, you put your UI in Activities. An Activity is, well, an Activity that interacts with the user. It’s similar to a Window in other  platforms – you fill the Activity with the controls you want and handle events as they occur. However, unlike any other platform I’m awareof, Activities die when you don’t expect them to. For instance, if the user turns the phone from portrait to landscape – your Activity dies, and another is created.

    The reasoning is to let Android take care of the new layouts for you – all the controls are recreated. Android takes care of copying their values (text the user entered prior to turning the phone), but it doesn’t take care of anything else. It doesn’t take care of your AsyncTasks, either. So if you run an AsyncTask that tries to notify the user after the processing is done, it does so through the Activity that created. By the time that AsyncTask is done, that Activity may not be around to be updated.

    There’s no easy way around this.

    Enter BetterAsyncTask! Next time I’ll describe a generic mechanism that handles it.

     

    Zmbq.

    Minimal Viable Product

    8 March, 2011 · By shai · Read More · No Comments

      A really amusing example for how minimal a Minimal Viable Product should be, from Bill Gross (the Hi-Tech entrepreneur, not the investor). This is an excerpt from his talk on Stanford’s Entrepreneurship Thought Leaders series. The link is to a 4-minute piece, with the story of interest about a minute in.

      http://ecorner.stanford.edu/authorMaterialInfo.html?mid=2667

      Self-hosting Python

      29 November, 2010 · By shai · Read More · No Comments

        PyPy is a very interesting project for making a Python with a compiler and a JITter, written in Python.

        Now, with the release of PyPy 1.4, they claim near-full compatibility with CPython 2.5 (they’re even working on C API compatibility; it seems that they’ve almost reached source-level compatibility, and binary compatibility is in the works). They also show a set of benchmarks where they’re much faster than CPython. The release message reported that the project members are using PyPy for most of their everyday needs, as a production tool.

        For those of you who may be wondering, PyPy also appears to be the third Python implementation to run Django (after CPython and Jython) — with the limitation that they’ve only tested it with SQLite.

        PyPy offers a host of other interesting features: A Stackless version, a selection of “back-ends” including .Net CLR and (unfinished) JVM, and considerable work on “front-ends” — other languages compiled by the same engine, including Prolog, JavaScript, and Smalltalk.

        This is a promising project, but it already delivers.

        Kudos to IBM

        28 October, 2010 · By shai · Read More · No Comments

          I happen to have a laptop. Quite an old one. Got it for one of our projects, back in 2005, and it’s been through quite a lot since then. About a year ago, it met the wrath of my children, and its space-bar broke in a way I couldn’t fix. Oh well, I figured, since it’s significantly out of warranty, and it’s IBM, there’s no use in using their lab. They’ll ask for half the price of a new one just to look at it. We all know IBM. Right?

          Wrong. One day in August, I did the retroactively obvious thing and phoned to ask them. Turned out they do the fix for free, and would only charge me for a spare keyboard if they didn’t have a replacement key available. As it happened, they did have all the parts they needed, and so they fixed it at no charge and on the spot. I spent ~15 minutes at the IBM lab, and now my laptop and me are back in business. And I even got a gift keyboard cleaner.

          Yes, it was a very minor fix (for them), of course. But I was very pleasantly surprised. I am now much more likely to buy my next laptop from them (or whoever they provide service for).

          XSS and SQL injection attacks attempted by Swedish voters

          27 September, 2010 · By shai · Read More · No Comments

            Sweden held general elections recently, and they allow people to write who they vote for by hand. Of course, some clowns voted for Donald Duck etc, but the more sophisticated disinterested voters tried to be more interesting

            (via slashdot)

            Marketing – Some Basics on How and When

            4 September, 2010 · By Shira Abel · Read More · No Comments

              You have the idea – now should you wait until you have a product to begin marketing? Or should marketing start in the product development phase? I’ve been doing marketing for start-ups for years now and know from experience, even though Marketing should be done from the very beginning, it’s typically held off until the product is close to finished. Why do I think this is a mistake? Because without some market research and understanding quite often products are made that aren’t actually needed in the market or good products have features that most people won’t like. Or the price to manufacture is seriously above the original planned market price (I did mention research is needed). And, as Google Buzz showed – what engineers think is important isn’t necessarily what the market will enjoy. (Remember how they thought automatically following people that you correspond with via Gmail would be a good idea – people didn’t like it. I’m not saying engineers aren’t people – but most people aren’t engineers…) Google Wave would be another great example of what was expected to be a revolutionary product ended up fizzling out to a sad meh of a death.

              Marketers (if they are good) should understand the voice of the customer and with that the needs and desires of the customer. Making a good that isn’t aimed at a customer is a waste of time. Products are meant to be sold, after all. And once that product is made – when is the right time to start the product launch? In reality – about 6 months before.

              Yes, that’s right – at least 6 months before actual launch.

              Why? Because launching a new product means buzz is needed – and unless you are Google, who can mention and launch a product in a day and every early adopter will be frothing at the mouth to get it (Hello Priority Gmail Inbox), then buzz takes time. If you’re a startup and don’t have the power of Google behind you, then you need to start your groundwork early. Who is your market? If you’re B2C (business to consumer) then you need to start targetting and building relationships with key influencers and bloggers in the arena you will launch. If you are a B2B (business to business) then the same relationships are required - but the aim is smaller, more focused. Either way your goal is to be mentioned with a positive tone in whatever publications your customer is interested in and by industry leaders that others listen to and respect. That can only happen by building up the relationship slowly, by giving a lot and by not asking for anything in return for a very long time. 

              When the time comes, you’re going to ask for one simple small thing: would you please try out my [product or service] for free? You aren’t going to ask them to talk about it. They’ll do that on their own if they like it. Which is exactly what you want – an honest opinion that people trust reported online.

              The Launch – Some of the Basics

              Every form of social media that you choose to engage in should be updated regularly. Blog posts should be at least once a week if not more – realistically it should be business week daily. Same with Facebook posts and Twitter. YouTube should be maintained. All pages should have backgrounds that are properly branded and a call to action should be optimized on all fronts.

              Facebook

              Have your Facebook page ready to go and make sure it’s optimized (landing tab, videos if you have them, FAQs tab if needed etc…). The method on Facebook changes depending on what kind of product you have. For B2Bs the focus will generally be on engaging the customer and giving them information that they will find helpful in their day to day operations. The goal here is to build reciprocity. If it’s a B2C product then typically the goal is to build community – which means that an editorial calendar is a good idea. Things to keep in mind:

              1. Which posts are getting the most response – and then figure out why.
              2. Which posts aren’t getting a response at all – and then figure out why.
              3. Call to action (i.e. Like, Share & Comment) - only one to three (one is best) per posts. More makes people confused and they end up doing nothing.

              Blog

              The main purpose of a blog is to grow your email list. Even with all of the different forms of social media marketing out there today – nothing beats a great newsletter campaign to get people to do things. The blogs should give information that is important to your customer. Posts should end with a question to encourage commenting – unless the goal of the post is to get people to buy, and then the comments should be turned off and a call to action should be at the very bottom of the post (this should be done very very very sparingly).

              The content has to be good and helpful or else people won’t sign up or read your blog.  

              Twitter

              My favorite way to engage.  However, it takes time and effort. There are various ways companies use their twitter stream:

              1. Promote sales & new products (DellOutlet)
              2. Social customer relationshionship management (Ford Customer Service)
              3. Building community and relationships (Scott Monty for Ford)

              YouTube

              It’s the #2 search engine online and you’d be amazed at how companies are using YouTube to market themselves.

              Conferences & Events

              Nothing beats meeting face to face. Planning which industry events are essential for networking should be done ahead of time. Especially since most major conferences start selling booth space at least 8 months before the next conference begins. Find out from organizers who will be at the conference and set up meetings with potential clients about 1 to 2 months before the conference begins.

              Webinars

              Want to let a lot of people  worldwide know what your product or service does? Do a webinar (and then post a portion of it on your YouTube page).

              Advertising & Sponsoring Events

              If your potential customers are at an event then sponsoring is a great way to get mind share. If they aren’t at the event then it’s a big waste of money. Make sure you’re certain they are there before spending the cash.

              Same goes with regular advertising.

              There’s loads of other ways to engage your market (location based services like Foursquare, Google Places and Yelp for example). Having a strategy mapped out ahead of time with goals and timelines in place is the best way to get there.  Do you think I’ve caught the main basics? What else would you add?

              So You’ve Got a Great Idea – Creating a Proof of Concept

              31 July, 2010 · By Shira Abel · Read More · No Comments

                So you have an idea. A great idea. The kind of idea that could change the world. An idea so amazing that you’re afraid to tell anyone about it – even your mother. People have started looking at you strangely because you’ve become so paranoid that you’re afraid someone will read your mind and steal The Idea.

                But will your idea work?

                When you have an idea for a new product, you should be able to explain what it is, what need it will fulfill and how it will do so. It’s also important to be able to prove, at least hypothetically, that your solution is capable of everything you think it is before you or anyone else invests in the idea. In other words, you need a proof-of concept (PoC). A PoC is used to carefully examine the need for a proposed solution early in its development cycle, and to figure out exactly what solution is required and how it will play out in the real world. This solution can be anything from a new type of electrical circuit, to a new medication, to a piece of hardware or software.

                By testing your idea in a PoC, you will be better able to determine how feasible the idea is, identify potential stumbling blocks, determine what features a given platform can or can’t provide and establish the scope and level of customization necessary to complete the project. If something either doesn’t work or is unfeasible, this is also a valid outcome – if you had skipped this step, you would have invested unnecessary resources in launching a product that doesn’t actually meet your needs. In other words “let’s not do it” is a valuable result, primarily because you’ll have invested a relatively small amount of time and money and saved yourself from an investment that would have been much more costly!

                Moreover, when looking for outside investors for your company or project, a proof of concept is usually required to demonstrate that the proposal is fiscally sound. For example, a company interested in developing a new suite of software would look at market demand, feasibility of the project, projected cost, and other factors.

                Your PoC should provide basic details regarding the need you are addressing. What type of individual, business or organization typically encounters this need? In what type of situation and at what point in the organization’s “life cycle”? Include a detailed description of the environment in which this need arises; for example, the PoC for a new software solution should include such details as the underlying hardware infrastructure and the operating system(s) in which this need is encountered.

                You may also want to briefly touch upon any existing solutions that are currently available and explain why they are not viable or complete solutions to the described need, while providing evidence that your solution is a better one. Describe your proposed solution in detail, together with all its features and capabilities. To continue with the previous example, this means including mockups of the user interface (e.g., all possible menus, screens, tabs, graphs, etc) as well as a list of the available modules, functions, sub-functions and so forth. Where relevant, explain how things will look and feel for different possible user roles. If your solution will incorporate third party tools or technologies, which ones and why? How will these additions be integrated into your solution? What obstacles have you foreseen and how will you address them? In software especially, security is often a primary concern, as is compliance with any existing standards and regulations.

                Be sure to address the financial and logistical aspects as well. How much is it costing the hypothetical customer to leave this need unresolved or to address it using other available solutions, and how much will it cost them to implement your solution? Explain the implementation process in detail: what is involved and how long it will take? Finally, describe how everything will play out in one or two test cases and check whether any adjustments need to be made.

                It’s important to note that a PoC is not the same as a pilot project. A proof of concept is intended to prove any assumptions in a non-production environment with no end-user involved, while a pilot’s goal is to verify, on the production network with live data and real end-users, that the vision of the project is being addressed.

                © Image courtesy of D’Arcy Norman

                Lightweight concurrency in Python

                27 July, 2010 · By shai · Read More · No Comments

                  Yesterday, in a meeting of PyWeb-IL, Uriel Katz presented different options of asynchronous networking (and general event handling) in Python. His favorite of the bunch was gevent, which is based on greenlet.

                  Greenlet is specifically interesting because it allows very lightweight “concurrency” — in the form of coroutines. This means that there’s no real concurrency, just “fake” concurrency (a function can let others run while it waits for something to happen), and the multitasking is cooperative. What you get for these limitations is very small consumption of system resources, compared with full-blown threads.

                  Python supports a form of coroutines out-of-the box, through generators, but they are not composable like greenlets (using a generator from a generator is cumbersome). Python also has a version that has lightweight threads with (optional) preemptive multitasking, called Stackless, but that involves patching the core interpreter. Greenlet, which is just a C extension for the normal interpreter, is an interesting middle ground between these two.

                  Cloud news

                  20 July, 2010 · By shai · Read More · No Comments

                    In the last couple of days, I came across two interesting announcements related to cloud computing:

                    • PiCloud is now offering its service to the public. It’s a cloud platform with a simple Python API (via the python-announce mailing list)

                    Thought you might find this interesting.

                    How to Develop a Winning Executive Summary

                    27 June, 2010 · By Ronit Goldstand · Read More · No Comments

                      As the old adage states, two heads are better than one! In today’s highly competitive global environment, entrepreneurs and small start-up companies are turning to joint ventures as a means to expand their power and scope and compete with the ‘big guys’.

                      For example, by landing a joint venture partnership, a small company with limited staff and resources can gain new capacity and expertise, be it technical or managerial, without investing tremendous resources.

                      Persuading potential partners to do business with you: The Executive Summary

                      The first step in forming a strategic alliance with any potential business partner is to create a well-written proposal that begins with an executive summary. An appealing, professional executive summary dramatically increases your chances of grabbing the attention of a potential investor or business partner.

                      An executive summary is just what it sounds like; a document that summarizes your entire concept into key points, so that a potential investor or partner can easily understand what your product is all about, and why s/he should be interested in what you have to offer.

                      The executive summary should concisely address the following:

                      1. A brief introduction, in which you include the background and history of your company, what your company does, and perhaps some basic information about your finances.
                      2. The unique features of your product or service, what makes it better or different from anyone else’s and the benefits it can provide to your potential partner and customers
                      3. Describe your target market, and discuss what your specific niche can provide for your company marketing strategy.
                      4. If possible, include references and testimonials, so that your prospective partner can see first hand how others feel about your product or service.
                      5. A persuasive statement as to why and how the business will succeed, discussing the business’s competitive advantage. It’s not enough to rely on being the first in a particular market as your sole competitive asset.
                      6. Projected growth for the company and the market
                      7. How much capital you need and how it will be used.

                      Tips on how forming an appealing Executive Summary

                      A good executive summary example summarizes your key points on the one hand, and appeals to your readers on the other. The following are some tips on how to do that:

                      1. Keep your summary brief – ideally, two pages or less. Think of it as everything you’d say to a prospective investor in a five-minute interview.
                      2. Avoid the use of hype. You need to be accurate, clear and compelling without trying to make your business or product more than it is, and promising anything that you can’t deliver.
                      3. Use legible font (Verdana is pleasing on-screen; Times New Roman is easy on the eye on the printed page).
                      4. Keep your headers brief (5-6 words), and write them in boldface, about one point size larger than your body text (body text should be 11 or 12 pt).
                      5. Start with your most important information at the beginning. Put your best face forward in a way that will attract your prospective audience, like the headlines on the front page of a newspaper.
                      6. Use an easy-to-read format, using simple sentences in short paragraphs that contain only relevant information. If your readers want more details, they’ll contact you.
                      7. Reread it when you are done and ask yourself, is it clear and concise? Will it compel the reader to contact you to learn more about what you have to offer?

                      Finally, you will probably want to send your executive summary through an email, so don’t overlook the way in which you introduce yourself and your company. Make it personal, introduce yourself by first name, and add your website and a short description of the products or service that you are offering. Be concise, but charming and persuasive at the same time. If your introductory email falls short, the executive summary that you worked so carefully on may not even get read.

                    • Language

                    • Blogroll

                    • Recent Posts

                    • Categories