Skip to main content

Posts

Showing posts from March 1, 2012

Key-Value-Observation — Looking for a more elegant solution to respond to value changes

I've run into a frustrating feature of KVO: all notifications are funneled through a single method ( observeValueForKeyPath:.... ), requiring a bunch of IF statements if the object is observing numerous properties. The ideal solution would be to pass a method as an argument to the method that establishes the observing in the first place, but it seems this isn't possible. Does a solution exist to this problem? I initially considered using the keyPath argument ( addObserver:forKeyPath:options:context: ) to call a method via NSSelectorFromString , but then I came across the post KVO Dispatcher pattern with Method as context and the article it linked to which offers a different solution in order to pass arguments along as well (although I haven't gotten that working yet). I know a lot of people have come up against this issue. Has a standard way of handling it emerged?

returning UIImage from block

I have the following code: - (UIImage *) getPublisherLogo { //check the cache if the logo already exists NSString * imageUrl = [NSString stringWithFormat:@"%@/%@&image_type=icon", self.baseUrl, self.imageUrl_]; ASIHTTPRequest * imageRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:imageUrl]]; [imageRequest setTimeOutSeconds:30.0]; [imageRequest setDownloadCache:[ASIDownloadCache sharedCache]]; [imageRequest setCacheStoragePolicy:ASICachePermanentlyCacheStoragePolicy]; [imageRequest setCachePolicy:ASIAskServerIfModifiedWhenStaleCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy]; [imageRequest setCompletionBlock:^(void){ UIImage *img = [UIImage imageWithData:[imageRequest responseData] ]; if (img){ return img; } }]; [imageRequest setFailedBlock:^(void){ NSLog(@"Error in pulling image for publisher %@", [[imageReq

What happens to my subView when changing navigation controllers?

Lets say that I add a subView to my view, like this: [[self addSubview:myView]; Then I push a new view onto the navigationController stack, like this: [self.navigationController pushViewController:otherView animated:YES]; What happens to the subView that I added to the original view. Is it removed automatically? Also, if my program calls this line: [[self addSubview:myView]; multiple times without removing the view does that do anything bad like create a memory leak?

Adding box2d header causes a torrent of compiler errors

I am experiencing either an extremely weird error or a temporary loss of brain function. I have a box2d / cocos project running in XCode. This all works fine but my code is currently a proof of concept "hack". Stage one of cleaning up the code is creating classes for various objects. Now, if I create a brand new Objective C class (inherited off NSObject) as below it all compiles fine. As soon as I attempt to import the "Box2D.h" I receive a gazillion errors originating from the box2d library saying it cannot be built. 201 to be precise and it indicates no issues with the class itself. Can anyone shed any light? I have already tried a clean and rebuild as well as restarting XCode. My super complicated class definition #import "Box2D.h" @interface test : NSObject @end An example compiler error thrown Expected '=', ',', ';', 'asm' or '__attribute__' before 'b2Fixture' in /Users/..../libs/Box2D/Dynamics

pushNavigationController on iOS 5 messed up my UINavigationBar when I pop back to the previous view controller

My main view controller only supports landscapeleft and landscaperight. This viewcontroller in the viewDidLoad has: if ([self.navigationItem respondsToSelector:@selector(leftItemsSupplementBackButton)]) { self.navigationItem.leftItemsSupplementBackButton = YES; self.navigationItem.leftBarButtonItem = homeBBI; NSArray *rightNavItems = [NSArray arrayWithObjects:searchBBI, allBBI, nil]; self.navigationItem.rightBarButtonItems = rightNavItems; } When I push my ReportViewController onto the stack, it looks fine. This controller also supports landscape only. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return UIInterfaceOrientationIsLandscape(interfaceOrientation); } When I rotate the iPad 180 degrees, all looks fine. However when I pop to the main view controller, the UINavigationBar gets messed up. It basically has all the items, including the title squished to the left. The search bar I had ends up taking up 75% of

Open MWPhotoBrowser with a link and loop

I'm fairly new at iOS development so please forgive my ignorance. I have web view with a search form, sending request to display different pages depending on the search query. When displaying a selected page I want to have a normal html link at the top which will give the user the possibility to display all images available using the very nice MWPhotoBrowser. So somehow I need to tell Xcode to open MWPhotoBrowser using a link and when this link is pressed send a variable to MWPhotoBrowser and in that viewController somehow loop through a my url.com/variable. Is this the best way to do this and is it even possible? I have searched as much as possible but I'm not sure what to look for so I would really appreciate if you could point me in the right direction.

Sending encoded XML to a server from iPhone

I'm communicating between an iPhone app and a server using XML. To get around the problem of the user entering any character that might break the XML before I send it to the server i'm using the NSString method: [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; But I noticed when doing a log of the string that the & symbol is not escaped? I thought that it should be? spaces, quotation marks and hash symbols which I've tested for all encode fine but not the ampersands? What is the most common methods used for encoding/decoding XML sent to/received from a server? Thanks.

Upgrade iPhone 3GS from iOS 4.2.1 to 4.3.x [closed]

Hi folks I have a iPhone 3GS at 4.2.1 and want to upgrade it to 4.3.x for testing. I have read some articles about it but it seems that those are too old and cannot work. Does anyone have some experience in doing this or does apple provide tutorials for developers in this? A lot of thanks.

Which member do I put my code in?

I'm writing my first SIMPLE DB app, basically, an offline db, select a listing of records, and then, click on one of those to display on the detail. I looked at an older book for an example (pre xcode 4) because it had an example very similar to what I needed to do. So the example set up all the methods I'd need to access the database in a member called DBAccess.m AND I can tell from the debugger that the code visits main.m and then MasterViewController.m it executes awakeFromNib and didViewLoad which is awesome... BUT where do I put my first statement that calls the routine I need that's in my DBAccess.m file? The book assumes you KNOW where to put your code and leaves it as an exercise for the user... ugh. I can't find any definitive statement about how you insert your code into the execution cycle. Is there a default execution cycle?

What does the origin control do in interface builder?

In interface builder there is a control in the struts and springs inspector that is labeled origin. What does this do and why does changing it for one object change it for ALL objects? As far as I can tell it doesn't have any real effect on the frame rectangle origin as the name implies. Let me explain: Selecting a UILabel and changing the origin to be at the top right as in the photo above puts the frame origin at the point (280,11). However, in code, when you actually ask the frame for it's origin it is given as (211,11) which corresponds to the top left corner of the frame. Therefore, changing the frame origin in interface builder appears to do absolutely nothing! What is going on here?!

how to write xml with objectiv-c and place it into an NSData object

I have been reading though heaps of the ios docs from apple, and almost every bit of code to do with xml on there requiers either creating a file with xml data in it or receiving xml over a connection then altering it. I would like to know if there is a way to just creat some xml.. maybe in a string, then convert it into a NSData object.. I know how to pass a nssting into a nsdata object.. thats not so much of a big deal.. the painfull part at the moment is getting some clear concise examples on how to create my own xml without all the other stuff that apple says you need.. I.e. file or return data. I currently have no code.. what I will likely do is create a method with some parameters that can receive some information and then pass them in to hopefully create a nice xml string/data object.. if you have any example code, suggestions links to decent tutorials that would be hugely helpfull :)

Issues submitting firemonkey app to app store

I have tried dozens of configuration settings trying to get this to work, but still to no avail... When I am trying to submit to the app store, the application loader is reporting the following error iPhone/iPod Touch: application executable is missing a required architecture. At least one of the following architecture(s) must be present: armv7. My understanding is that fpc 2.4 can only generate armv6 code anyway. I have tried setting all build settings to only reference armv6, installed the previous version of XCode 3.2.6 and linked with the iOS SDK 4.3, hoping that this will address any references to armv7, but still no joy. According to the XE2 Update 4 release notes, fpc 2.6 supports armv7, but despite the release notes having been available for weeks, there is no sign of the update! Has anyone successfully uploaded an app using current tools (it surely has to be possible), and if so, could you please share your secret! Thank you

iOS import causing tons of errors?

I'm trying to set up a menu in my cocos2d game and whenever I import Game.h I end up with over 200 errors. It's a cocos2d app with box2d, I'm not sure why it's throwing all these errors though- the game was running perfectly before I swapped loading the Game scene for the MainMenu scene initially. The line of code I'm running is [[CCDirector sharedDirector] replaceScene: [Game node]]; The import of 'Game' causes the errors. Can anyone give me an idea about this? Some information that may be helpful... I originally created the project loading into Game.m but switched it to MainMenu and then import Game.h into MainMenu to access the object. ANY insight is appreciated! Thank you!

Loading NSData into a UIWebView

In my web browser, I am trying to load a UIWebView with NSData obtained from an NSURLConnection. When I try to load it into the UIWebView, instead of the site, it comes up with the HTML plain text. Here is my code: in viewDidLoad: NSURLRequest *request = [NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.msn.com"]]; [NSURLConnection connectionWithRequest: request delegate:self]; later in the code: -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ webdata = [NSMutableData dataWithData: data]; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection{ [webview loadData:webdata MIMEType: @"text/html" textEncodingName: @"UTF-8" baseURL:nil]; }

Is a "CFRelease” needed if I am using CGImageSourceCreateWithData from a (__bridge)?

My question is very simple, I would like to know if the method "CGImageSourceCreateWithData" creates a new object copying the data I provide so that that I have to release it when I don't need it anymore, or if it just creates a reference to the data I already have so that if I release it I will lose this data (and possibly have bad access errors). The issue is related to using (__bridge CFDataRef) as the source data. Which let's me use Core Foundation objects as toll-free in ARC mode. Consider the following function (or method, not sure how it's called): - (void)saveImageWithData:(NSData*)jpeg andDictionary:(NSDictionary*)dicRef andName:(NSString*)name { [self setCapturedImageName:name]; CGImageSourceRef source ; // Notice here how I use __bridge source = CGImageSourceCreateWithData((__bridge CFDataRef)jpeg, NULL); CFStringRef UTI = CGImageSourceGetType(source); NSMutableData *dest_data = [NSMutableData data]; // And here I use

connectionDidFinishLoading called before didReceiveData with rails production sending photos

I have a rails 3.0.3 website that, in development mode, responds to a HTTP GET by calling didReceiveData and then connectionDidFinishLoading, and photo data is sent from the website to the iPhone and displayed correctly. But when I run the rails 3.0.3 website in production mode, connectionDidFinishLoading is called before didReceiveData. I'm using carrierwave to handle the photos for both the development and production rails sites. Does anyone have any idea what could cause connectionDidFinishLoading to get called before didReceiveData? I've tried checking the following: 1) I made sure the NSURLConnectionDelegate is called for the class' interface. 2) didReceiveResponse gets called before connectionDidFinishLoading and the statusCode = 200. 3) In the rails app I am using send_file to send the photo data, and the path to the file sent in production, is an actual photo. 4) I checked that data was being returned from the production website by using the code below

How does the iPhone Google image search touch-event functionality work?

When I do a Google image search on my iPhone within the Safari mobile browser, it gives me this beautiful interface for flipping through the images. If I swipe left or right, it browses through the images. If I touch and move up or down, I get what appears to be the native Safari scroll function. Can anyone explain how Google does this? I'm only beginning to learn the Safari API for touch events. It seems like either you capture the touch event to attach handlers to swipe left or right or you let Safari handle the touch events natively, in which case you get the beautiful native Safari scrolling. Can anyone explain how Google captures left/right swipe but not scrolling?

Writing an Android library - Using its own custom Application class (getApplication)

I'm writing an Android library and I wish to use a custom Application class, which will be accessible from all of the library's activities (using the getApplication method). The problem is when I call the getApplication method from one of my library's activities, it returns the application class of the app using my library (and not the custom class I declared in the library's Android manifest). My current guess (based on this answer and the official documentation ) is that the application using my library must also declare the custom Application class in their Android manifest - which is a problematic solution, since that application can also have its own custom class (and a single app cannot have more than one custom Application class, right?). Can anyone offer a better solution? (or verify that this solution is accurate) Any help will be appreciated..

Image is not fit into QuickContactBadge

I have create a listview of Contact numbers , the list item contains the QuickContactBadge and TextView now whenever i tried to load image into QuickContactBadge it does not get fit into the QuickContactBadge Frame and at the same time QuickBadgeContact itself will also get shrink. Rite now i have this What i am trying to achieve is so not only image but even i am trying to make QuickContactBadge of a normal size here is my code that i am using Uri contactUri = Uri.withAppendedPath( ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactId)); InputStream input = ContactsContract.Contacts.openContactPhotoInputStream ( getContentResolver(), contactUri ); cache.photoView.setImageBitmap(BitmapFactory.decodeStream(input)); My Layout for list item <QuickContactBadge android:id="@+id/badge" andro

uploading image on web: getting html source code as response

I am trying to upload image on web server, but whenever it tries it is sending me html source code as response and image is not uploaded there. My code is: HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); bitMap.compress(Bitmap.CompressFormat.JPEG, 100, byteStream); byte[] buffer = byteStream.toByteArray(); ByteArrayBody body = new ByteArrayBody(buffer,"profile_image"); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); entity.addPart("b@gmail.com.jpg", body); post.setEntity(entity); System.out.println("post entity length "+entity.getContentLength()); ResponseHandler handler = new BasicResponseHandler() ; String response = client.execute(post,handler); Thanks in advance!!!

String Array doesn"t show the expected value

I have a String array initialized globally Like: String[] links={""}; in an onclick listener i m putting some values in it using a for loop links = new String[Link.size()]; String[] news = new String[Catagory.size()]; for (int k = 0; k < Catagory.size(); k++) { news[k] = Catagory.get(k).toString(); if (news[k].contentEquals("Android Apps")) { links[k] = Link.get(k).toString(); Toast.makeText(getApplicationContext(), links[k], Toast.LENGTH_LONG).show(); SHOW.add("Title:" + "\n" + Title.get(k) + "\n" + "Date:" + "\n" + PubDate.get(k).replace("+0000", "") + "\n" + "Content:" + "\n" + Content.get(k).replace("<br/>", "") + "\n"); Log.i("IF ELSE", Catagory.get(k)); } } and its happening

If Push Notification is disabled and Push Messages are sent, when are they get recived?

In my Android App I have used UrbanAirship to receive Push Notification. My web application sends me the notifications, which works great. Now if my Push is disabled in my Android apps Push Preference, I am not getting any push messages - which works as expected. Now I made my Push Enable, Quick Question - when will my app receives those notification sent by my web app when my App was in disable mode. Thanks, Panache

ListView doesn"t stop on finger up?

I have a listView which defined like this in xml: <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginTop="150dp" android:layout_x="4dp" android:layout_y="183dp" android:cacheColorHint="#00000000" android:fadingEdge="vertical" android:enabled="true" > </ListView> Everything's just fine, but in a strange way if user wants to scroll the list down to see other items and gets his finger up list turns back to top ? It's just not stopping where user scrolled... Why could it be happening? Thanks for help in advance...

force android tests to run on different emulators from command line batch file

How can I run my android junit/robotium tests from the command line on every single emulator? I want to make sure my tests run on many android OS versions and many screen resolutions. I'd like to write a batch file that runs from the windows command line to run my test suite over and over again on each emulator I have installed. To run from the command line I can do this: adb shell am instrument -w com.myapp.client.test/android.test.InstrumentationTestRunner but that just runs it on the default emulator. How can I force that command to run on all of the emulators I have setup? Ideally, the batch file would looking something like: launch emulator1 run tests close emulator1 launch emulator2 run tests close emulator2 ... I don't know how to do the launch and close part. Thanks EDIT: Found solutions. Below is my batch file set PORTRAIT=medium set LANDSCAPE=large :: launch emulator emulator -avd android2.2 :: wait for emulator to l

NullPointerException - What to do?

I'm experiencing a NullpointerException with this code: kuglebutton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(toggle.isChecked()) { counter1 = counter1 + 10; column1tv.setText("" + counter1); } else { counter1 = counter1 - 2; column1tv.setText("" + counter1); } } }); Can anyone tell me what i'm doing wrong, and maybe how to fix it?

Android: how to open new intent from ListView, hosted in TabHost, inside same FrameLayout?

I looked through tons of articles how to open new Activity from ListView hosted by TabHost. I have a TabHost Activity, one of the tabs has ListView, with clickable list items. On item click, I want new Activity to be opened in the same FrameLayout. My code for calling new Activity looks as following: Intent intent = new Intent(v.getContext(), displayRSS.class); this.startActivity(intent); This opens just new Activity. I want new Activity to be opened instead of current ListActivity. Would appreciate any possible solutions on this.

Boot up Broadcast Issue?

My Application is working fine with other devices, however the BOOT broadcast is doesn't working at all in Samsung ACE. Any workaround for this? Manifest File <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="a.b.c" android:versionCode="1" android:versionName="1.0.0" > <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name"> <receiver android:name=".BootupReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver> </application> </manifest> Java Class package a.b.c; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import andro

Location permission only for the ad platforms: Is it worth it?

I'm considering add location permissions to my app (Android) in order to pass that location to the ad platforms (currently Admob and Mobfox). But I don't want to make it if it doesn't worth it because ask for location in my app have not sense from the point of view of the user. Does someone have tested how the location affect on the CRT, eCPM ...? Thanks

Android button with image background and text and stateful functionality

I want to create "button" in XML layout (if possible) which has background image based on state (this image is NOT 9-patched) and with text. Which component to use? My button_states.xml looks like: <?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/my_pressed" /> <item android:drawable="@drawable/my_normal" /> </selector> my_pressed and my_normal are NON 9-patched images. Now if I use regular button <Button android:id="@+id/my_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/button_states" android:text="@string/my_text" /> button it is rendered without background image. How to do "button" with text a

App crashes when you click several times

In my app the first screen is a list and when you click once it goes ok but if,my mistake or something, you click two or more times before it loads the application crashes. I've been doing a little research but I didn't found anything. I post my code: @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.firstscreen); // Set title getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.mainheader); // Get Arguments Bundle extras = getIntent().getExtras(); if (extras != null) { app = extras.getString("app"); } //Set simulation date TextView date = (TextView) findViewById(R.id.date); date.setText(convertDateToString()); // set the list adapter: ListView myList = ListView lv = (ListView) findViewById(R.id.list); DataBaseAccess ddbb = new DataBaseAccess(); //Download the data from a dat

database insertion working well on android emulator but not on device

I have created a database using this tutorial . When I insert the values in my table, it works on the emulator and I have seen the values are inserted correctly. But when I run my application on a device, it gives me this error: 02-29 17:30:45.341: E/Database(3300):android.database.sqlite.SQLiteException:no such table: recently_used: , while compiling: INSERT INTO recently_used(iconsset_name, icon_name) VALUES(?, ?); 02-29 17:30:45.341: E/Database(3300): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method) 02-29 17:30:45.341: E/Database(3300):at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92) 02-29 17:30:45.341: E/Database(3300):at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65) 02-29 17:30:45.341: E/Database(3300): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83) 02-29 17:30:45.341: E/Database(3300): at android.database.sqlite.SQLiteStatement.<init> (S

Catch any touch in the screen in a service

I need a service that know if the user is touching the screen anywhere. If user doesn't touch the screen in a time, I launched a intent to the browser. Someone can help me. I cann´t find the code of how to capture any touch on screen in a service and I cann't think in any solution. Sorry for my English and thanks.

Android UI align button at the bottom of scrollview

I want to place a button of the screen in the below layout. The challenge is that there is a scroll view in the layout that does not have enough content to fill the parent. Here is the layout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:weightSum="100" > <ScrollView android:id="@+id/svAnsSum" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="100" > <LinearLayout android:id="@+id/llAnsSum2" style="@style/CodeFont.BlueText" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" >

No repository found error in Installing ADT in eclipse Indigo

This error comes when I try to install ADT: An error occurred while collecting items to be installed session context was:(profile=epp.package.jee, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=). No repository found containing: osgi.bundle,com.android.ide.eclipse.adt,16.0.1.v201112150204-238534 No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.adt,16.0.1.v201112150204-238534 No repository found containing: osgi.bundle,com.android.ide.eclipse.ddms,16.0.1.v201112150204-238534 No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.ddms,16.0.1.v201112150204-238534 No repository found containing: osgi.bundle,com.android.ide.eclipse.hierarchyviewer,16.0.1.v201112150204-238534 No repository found containing: org.eclipse.update.feature,com.android.ide.eclipse.hierarchyviewer,16.0.1.v201112150204-238534 No repository found containing: osgi.bundle,com.android.ide.eclipse.traceview,16.0.1.v201112150204-

Encrypting a folder for an Android app?

The app I am working on gets all the files from the sdcard but these files are really important and the app should maintain a security issue .So is there a way that the folder or directory that contains the file may be encrypted or locked with a key and only be used by my app? Please help I am newbie and stuck at this point.

setting different imageview of expandableListview

Hello everyone I worked with this tutorial for ExpandableListView with checkboxes: link to tutorial . Subsequently I needed the same example but instead of checkboxes I have to put the ImageView I got to do it but the problem that I do not want every child will have the same images, so I have not found how to pictures of each child in each group of expandable list! if anyone can help me!

how generate xml from java object in android

i have a array list with values. The user will add some values to my ArrayList and i want to serialize it to xml file to response to server to avoid using a database for this little option and of course TO LEARN how to serialize (i'm a begginer) because it seems useful. Anyways the user save something in the arraylist, the program shuts down, the program starts up again and the user is able to see the saved data. How can i implement this? Can you provide some code snippet or a useful link? Thanks a lot!!

audiorecord is not working properly while using audiotrack in galaxy y

i have written a code which records voice using audiorecord and at the same times it plays that recorded sound using AudioTrack. the main portion of the code is following - AudioRecord audioRecord = new AudioRecord( MediaRecorder.AudioSource.MIC, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, 16 * 1024); audioRecord.startRecording(); AudioTrack audioPlayer = new AudioTrack(AudioManager.STREAM_VOICE_CALL, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, 16 * 1024, AudioTrack.MODE_STREAM); audioPlayer.play(); for (int i = 0; i < 500; i++) { int n = audioRecord.read(recordBuffer, 0, 160); audioPlayer.write(recordBuffer, 0, n); } ........... This code works perfectly in other device . but in galaxy y , its creating problem. in galaxy y its showing obtainbuffer timed out in audiotrack. i run this code successfully in other devices. and i also checkhed that if i write the recorded sou

Android database closed exception

I'm working on a project where I'm downloading and saving data from web to sqlite database. A few minutes ago I receive a strange exception to our server from a user which is saying that the sqlite database is already closed..and I just checked the whole file where the exception happened and I'm not calling dbHelper.close(); . Here is the function where the app crashes and LogCat message : public void insertCollectionCountries(JSONObject obj, Context context) { //Insert in collection_countries if(RPCCommunicator.isServiceRunning){ Log.w("","JsonCollection - insertCollectionCountries"); ContentValues valuesCountries = new ContentValues(); try { collectionId = Integer.parseInt(obj.getString("collection_id")); dbHelper.deleteSQL("collection_countries", "collection_id=?", new String[] {Integer.toString(collectionId)}); JSONArray arrayCountries = obj.getJSONArray("

Android Thread Concurrent running threads notify between them

I want to execute the method uploadingDone() after completion of all three threads. The flags are working most of time correct. In rare case all three flags set to true and BLOCK1 get executed twice. All three threads are doing different tasks on different data ( No Concurrent modification can occur). Can I eliminate the flags with any native function on thread? All three threads to be run in parallel(Mandatory Requirement.). BLOCK1 should be called only once . private synchronized void uploadingDone(){ if( isItemUploaded && isListUploaded && isStoreUploaded){ uploadingDone = true; //<BLOCK1> //TODO move to next screen }else{ Log.i(TAG, "uploadingDone: Failed"); } } private boolean isListUploaded = false, isItemUploaded = false, isStoreUploaded = false, uploadingDone = false; private class ListUpload extends Thread{ @Override public void run() { isListUploaded = true; Log.i(TAG

Android app crashes on load - classNotFoundException

This has been driving me mad for a couple of days :) IDEA is my weapon of choice. During an editing session of inconsequential changes (or so I thought) of adjusting layouts, nudging buttons a few pixels left to line up etc I compiled and ran the project. I got a ClassNotFoundException when my app starts. It is thrown by java.lang.Bootloader. I put a breakpoint on the call to the Bootloader and can see that the offending class is my main application class. Here's how it looks: public class Rands extends Application{ public static SharedPreferences preferences; private static ArrayList<Favourite> favourites; private static Rands instance; public Rands(){ instance = this; } and in the manifest: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="rands.mycompany.com" android:installLocation="preferExternal" android:versionCode="8" android:versionName=&qu

Android: JSONObject cannot be converted to JSONArray

I want to get data from php file to Android using JSON. This is my code: .... HttpEntity e = r.getEntity(); String data = EntityUtils.toString(e); JSONArray timeline = new JSONArray(data); JSONObject last = timeline.getJSONObject(0); return last; When I debug the program there is JSONException on this line: JSONObject last = timeline.getJSONObject(0); data = {"a":1,"b":2,"c":3,"d":4,"e":5} and the Exception is: "org.json.JSONException: Value {"d":4,"e":5,"b":2,"c":3,"a":1} of type org.json.JSONObject cannot be converted to JSONArray"

Android Packaging: Error generating final archive resources.ap_

I'm currently trying to build a PhoneGap project I've been working on in Eclipse. However, when I try to build and run the project on the Android Emulator, I get the following error... Error generating final archive: Failed to add /Users/me/Projects/MyApp/bin/resources.ap_ Unknown Android Packaging Problem I've cleaned the project several times, removed the resources.ap_ file, as well as the contents of the gen directory. Anything else I can try? Much appreciated. <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="my.app.android" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <supports-screens android:largeScreens="true" android:normalScreens="true" android:smallScreens="true" android:res