I'm creating an app that has backround services/broadcast recievers... a lot of seperate threads are running.
What would happen if one thread is writing to file.txt with an FileOutputStream object, and another thread then attempts to write to the same file.txt with another FileOutputStream object?
Would the second thread wait until the first one is finished? Or do I need to implement FileLock in my android app?
Also what happens if I try to read with FileInputStream while another thread is writing to that file with FileOutputStream?
Thanks!
-Brian
Related
I asked this question on stackoverflow but it's getting (literally) no views for some reason so I'll repost it here.
hxxp://stackoverflow.com/questions/3321047/search-suggestions-fail-in-2-2
(new users can't post links)
My application uses in-app search, dynamically builds search suggestions on each request, puts them in a MatrixCursor and returns the suggestions to be displayed. Info on search suggestions here:
hxxp://developer.android.com/guide/topics/search/adding-custom-suggestions.html
This works perfectly fine in 2.1-update1, but when I loaded it on a 2.2 phone, I get a fatal error when I try to search. The error logs are in the link, but basically the application is getting an error in code that isn't mine (Google Android code for displaying search suggestions - SuggestionsAdapter). For some reason it's trying to get the MatrixCursor to Long.parseLong() a String, and the application is failing. Again, this does not happen in 2.1. I hope I've just overlooked something stupid.
Thanks!
Hey there,
I started developing Android Applications a few days ago.
Now, I wrote a Program wich is about to call a new class/activity.
But always when I launch the Program and it want to call the new activity, the errormsg "Source not found" occurs in the debugger.
I created the class with a leftclick on the existing class-file -> new -> class.
I know, the Internet is full with informations about "Source not found" but i didn't find any informations about exactly this issue.
Would be nice, if someone could tell me, what I did wrong...
Thx and greez Visosilver
Please elaborate on what you are doing. Does your app start? Does this happen when you are debugging your app?
I imagine that you are debugiing and stepping through the code. If you try to go into a method from the framework you need to attach the source code for the framework otherwise you get the message "Source not found"
Hi .
Im trying to do an aplication for practice exam test but i have a lot of doubts.
Well, the first is when you launch the app, it have to load automatically the test from a specific folder. I dont know how to make that.
Second is about how can i "tell" to the app where answer is the right.
with a T and making a space between questions for autodetect questions, like this example...
1. Which number is 2+2?
F. 5
F. 6
F. 2
T. 4
2. Which letter is the last from abecedario?
T. z
F. t
F. j
F. m
Click to expand...
Click to collapse
Im a noob programe, in fact, i dont know anything about programming and all that i know is about reading the book "Hello android" but i need to do this app for practice my exams because i didnt found any app like that.
anyone can help me with that?
Thanks in advanced
This seems like a good exercise for you to learn about Android development or Java development in general. You should definitely learn the basics of Java development first, there exist already topics on this (i.e. http://forum.xda-developers.com/archive/index.php/t-660598.html)
Some more specific help for your problem. I will only give a suggestion on how to do this. You could for instance have a folder (say myquestions/) where you put all your questions in (question1.txt, question2.txt).
Code:
File externalDir = Environment.getExternalStorageDirectory();
File questionDir = new File(externalDir, "myquestions");
Now you can list all files in your myquestions directory and read/parse the contents.
Code:
try{
for (File questionFile : questionDir.listFiles()) {
BufferedReader in = new BufferedReader(new FileReader(questionFile));
//Read and parse your questions
while ((strLine = in.readLine()) != null) {
// You should parse your lines here
}
in.close();
}
}catch (Exception e){
//Catch exception if any
}
To parse your answers for T or F you can use existing String methods like indexOf(), substring(),...
I did not test the above code, but it should get you started.
Good luck!
Stijn
Thanks for your help spolfliet.
After reading your contents im now sure that i cant do my app, its too hard for a noob and i cant waste time in learning now java... the book "Hello Android" its useless in that case.
Better i prepare my exams in paper but i will open a new thread with photos and descriptive text about the test examinator that i try to do, for if anyone wants to do that and help people preparing exams, because in the market doesnt no exist anything like that.
Thanks spolfliet
I new to android and same for web services. I want to learn how to use PUT request for placing file on a url. But I couldn't find any sample or tutorial for doing so.. Please help me by providing any tutorial or anything...
I know this is not the place for such questions but I have been searching for long but couldn't find any solution.
Well there are several way to get it:
1.) Using standard HttpClient
2.) Using an external library like Volley
It is up to you to choice the right way, you should consider how complex is your application.
You can search on google using Android HTTP Client: GET, POST, Download, Upload, Multipart Request
you can find a full tutorial explaining how to to use HTTP connection to invoke a WS.
Bye
Need help with project. Getting "unhandled exception java.text.parseexception" error
Hi, in my android studio project, I have been getting an error and I've been trying to resolve it for the last couple hours. Sorry about my links, apparently since I'm new I can't post links yet... So I spaced out my links.
//
The error is: "Unhandled exception:java.text.ParseException"
This error pops up on the following three lines in my code. My full code is located on onedrive at this link: (1drv.ms / 1NatGWH)
Date date1b = format1.parse(endtime1);
Date datenow1 = format1.parse(currenttime1);
//
What I want my app to do:
When I click a button, I want the code to check what time is it and if it is between two times listed. If so, it will then display my next school course that day.
I have a working eclipse version in which it prints what I have next into console. But now I want to make it into an app. The link containing the java file explains pretty well what I want my app to do. It is accessible here at this link: (1drv.ms / 1SBrFki)
Help would much be appreciated. Feel free to ask me questions.
Matthew