android-activity

How to save activity state after pressing back button?

馋奶兔 提交于 2020-01-25 07:04:26
问题 I have 2 activities A and B first one having products list and second one is the shopping cart. On click of a button in the list I am adding products to the cart. Now I go to the cart and delete some items from it. I press back and came to the activity A again. Now if I go to the B(cart) again the list is null i.e there are no products in the cart. I am using onSaveInstanceState and onRestoreInstanceState to save an restore the instance of cart activity but that is not working. Perhaps this

Is there a method to clear all the task in an app (Android)?

爱⌒轻易说出口 提交于 2020-01-25 06:57:28
问题 Quick question, just want to know if i have 2 tasks in my project. Is there any way to clear both of them in a single go. This is because when i try to clear both task to quit my app, only one is clearing and the another one is still alive which prevents me from quitting the application. finishAffinity(); int pid = android.os.Process.myPid(); android.os.Process.killProcess(pid); Any suggestions to solve this ? 回答1: Yes, You could use: FLAG_ACTIVITY_CLEAR_TOP FLAG_ACTIVITY_SINGLE_TOP FLAG

How to mail TextView data on button click with Android-Intent?

杀马特。学长 韩版系。学妹 提交于 2020-01-25 05:39:24
问题 I am pretty new to both android and NFC . I am working on an NFC related application as a college project that reads the data from tags and lists them. Although I am able to do so, I am facing problems with intent where I am supposed to mail this list to user on button click. Can someone please tell me where I am going wrong and help with a detailed step-by-step approach. Huge thanks..!! Here's the WebServiceActivity : public class WebServiceActivity extends Activity { Intent intent =

Can't read a file for strange reason [duplicate]

笑着哭i 提交于 2020-01-25 04:41:26
问题 This question already has answers here : Why I can't read a read only file? (2 answers) Closed 5 years ago . I have these methods for reading and writing to a file: /* Write content to a file */ private void writeToFile(ArrayList<String> list) { File file = new File("jokesBody1.bjk"); FileOutputStream fos; if(list != null){ try { file.createNewFile(); fos = openFileOutput("jokesBody1.bjk",Context.MODE_PRIVATE); ObjectOutputStream out = new ObjectOutputStream(fos); out.writeObject(list); out

Get access to Zxing QR scanner camera view

好久不见. 提交于 2020-01-25 00:17:05
问题 I am new to android development and I am working on an android project where I have to integrate QR scanner. So I thought I would integrate Zxing QR scanner and came across this library https://github.com/dm77/barcodescanner, Following the instructions provided I have successfully integrated and scanned a QR as well. Now I want to customise the camera view. The problem is there is no documentation on how to get access to the camera layout. Since I am new I might be missing something. I have

How to make EditText regain focus?

守給你的承諾、 提交于 2020-01-24 19:26:25
问题 I have one activity with an EditText and a button. When the button is pressed, I call myEditText.setClickable(false); myEditText.setFocusable(false); I have another button, which when pressed, changes the activity. Intent myIntent = new Intent(view.getContext(), DestinationScreen.class); startActivityForResult(myIntent, 0); When I return from activity2 to my main activity which has the EditText, I want it to regain the focus. That is, I want to be able to type in some new values in it. Any

How does a Service communicate with its Activity? How can a Service call a method in the Activity, which started that Service?

岁酱吖の 提交于 2020-01-24 12:55:06
问题 Suppose I have an Activity that's a list. It calls a Service when this Activity starts. The Service will do background stuff--download, parse, and fill the list. My question is this: How can the Service communicate with the Activity ? How can I call a method in the Activity, from the Service? (I'm new to OOP) The Service is started like this: hello_service = new Intent(this, HelloService.class); startService(hello_service); One of the things my service does is download and parse an XML. After

Android finishing activity from class view by touchEvent

谁说我不能喝 提交于 2020-01-24 12:06:20
问题 I have got class GameActivity and in there a method setContentView(GameView) . In class GameView which extends View I have got a method: public class GameView extends View{ ... public boolean onTouchEvent(MotionEvent event){ switch(event.getAction()){ case MotionEvent.ACTION_DOWN: Intent intent = new Intent (contexTmp, MainActivity.class); contexTmp.startActivity(intent); //finish(); //->how to finish this activity from class view } } } As you can see in class GameView in method onTouchEvent(

Android finishing activity from class view by touchEvent

﹥>﹥吖頭↗ 提交于 2020-01-24 12:06:08
问题 I have got class GameActivity and in there a method setContentView(GameView) . In class GameView which extends View I have got a method: public class GameView extends View{ ... public boolean onTouchEvent(MotionEvent event){ switch(event.getAction()){ case MotionEvent.ACTION_DOWN: Intent intent = new Intent (contexTmp, MainActivity.class); contexTmp.startActivity(intent); //finish(); //->how to finish this activity from class view } } } As you can see in class GameView in method onTouchEvent(

Android Lunar Lander thread handling alternatives

回眸只為那壹抹淺笑 提交于 2020-01-24 10:59:07
问题 Like many of the novices of android programming, I used Lunar Lander as a guide for implementing the SurfaceView. I'm practicing by creating a version of PONG. The basic structure of the code is the same as LunarLander. Obviously, I soon discovered the bug that was in Lunar Lander. The immediate way I got around this is by instantiating a new Thread object in SurfaceCreated() and starting it, when the original thread can't be started (which incidentally, is the same method that a lot of