android-activity

Send data from Service back to my activity

被刻印的时光 ゝ 提交于 2020-01-01 12:12:14
问题 I have an activity that creates an intent, puts some extras with putExtra() and calls the startService(intent) to start a service. This service calculates some stuff based on the extras and then I want to send the result back to the activity. In which way can I do this? I tried to create an intent on my service and broadcast it using sendBroadcast(). I have a broadcastReceiver on the activity but Im not sure if I register it correctly. Im confused! Is there any other way to do so? Something

How to pass spinner data from one activity to another ?

天大地大妈咪最大 提交于 2020-01-01 10:16:13
问题 This code is not reading the value from the spinner it's reading only the first value always, btnResult.setOnClickListener(new View.OnClickListener() { final String USN = spnConversions.getSelectedItem().toString(); @Override public void onClick(View v) { Intent i = new Intent(getApplicationContext(), DatabaseResult.class); i.putExtra("getData",USN.toString()); startActivity(i); } }); 回答1: Why you are using onClickListener for Spinner ? You should use OnItemSelectedListener() for Spinner see

Up navigation and saved instance data

a 夏天 提交于 2020-01-01 08:59:07
问题 An app has 2 activities, A and B. A has instance data that is saved @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("foo", 0); } and A has int bar; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // ... if (savedInstanceState != null) { bar = savedInstanceState.getInt("foo"); } else { bar = -1; } } to restore the data. Activity B has the actionbar enabled and @Override public void onCreate

OnTouchListener: Swiping across the screen

孤人 提交于 2020-01-01 07:08:10
问题 Please have a look at the following code. I am ONLY posting the important sections of the code. activity_game.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fullView" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal

Create Simple gesture for swipe left to right and right to left

女生的网名这么多〃 提交于 2020-01-01 07:04:44
问题 I want to create simple swipe gestures between two activity ,i have searched a lot got something like below.But my doubt is how could i swipe the activity or view using swipe gesture!! class MyGestureDetector extends SimpleOnGestureListener { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) return false; // right to left swipe if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE &&

Can't start an activity from a cordova plugin using .aar files

血红的双手。 提交于 2020-01-01 06:37:12
问题 I am trying to write a simple cordova-plugin for android, but I am stuck into a crash that I don't know how to resolve. I basically followed these steps to create simple plugin and it worked fine. http://www.mat-d.com/site/tutorial-creating-a-cordova-phonegap-plugin-for-android-app/ Yet, my plugin must call an activity that is packaged as an .aar file. Basically I have a full blown application with java/layouts that needs to be triggered by the plugin. I followed these steps to add my .aar

Why is my rotate animation all wonky when applied to an Activity transition?

早过忘川 提交于 2020-01-01 05:42:08
问题 What is the below animation supposed to do? <?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:interpolator="@android:anim/linear_interpolator" android:duration="1000" /> Easy enough. It should represent a clockwise rotation about the centre. Just spin around once, then stop. Right? And so it does... when I apply it to a View. But when I

How to make space between spannable string in Android?

为君一笑 提交于 2020-01-01 05:29:09
问题 Code: private void setSpans(Editable s, @ColorInt int backgroundColor) { BackgroundColorSpan[] spans = s.getSpans(0, s.length(), BackgroundColorSpan.class); String[] words; if (s.toString().endsWith(" ")) { words = (s.toString() + "X").split("\\s"); } else { words = s.toString().split("\\s"); } int completedWordsCount = words.length - 1; if (spans.length != completedWordsCount) { for (BackgroundColorSpan span : spans) { s.removeSpan(span); } int currentIndex = 0; for (int i = 0; i < words

Android Rendering Problems Couldn't resolve resource @string/app_name

左心房为你撑大大i 提交于 2020-01-01 05:05:09
问题 I'm new to android programming and I don't understand what I'm doing wrong. I try to make a button like this in the xml file: <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/btnText" android:id="@+id/button" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> This works fine, without the android:text="@string/btnText" part... My strings.xml file looks like this: <string name="btnText">GO!</string> I get this

Handle orientation change with running AsyncTask [duplicate]

六眼飞鱼酱① 提交于 2020-01-01 04:56:05
问题 This question already has answers here : Best practice: AsyncTask during orientation change (9 answers) Closed 4 years ago . Use case: The user start the app that will load a captcha. The user fill the captcha and try to download some information. Problem: If the user rotate the device while downloading the Activity is destroyed. At the end of the execution the AsyncTask is trying to update the destroyed Activity and the result is a "View not attached to window manager". "Wrong" solution: I