android-activity

What is the correct way of creating a login screen/activity in Android?

大兔子大兔子 提交于 2019-12-29 10:12:12
问题 I am working on an Android application that requires a user to login before doing anything else. Currently I have created main Activity named LoginScreen and upon successful login this activity launches another Activity called Home. But I see a problem with this approach. What if user presses back button from Home activity? I dont want user going back to login screen. what is the correct way of stopping the user from doing that. Do I need to handle Key Press events? 回答1: What I ended up doing

Button onClick error…Could not find a method

徘徊边缘 提交于 2019-12-29 09:40:24
问题 I can't seem to start a new Activity from my Button , I have searched here for answers, but can't seem to resolve the problem. I hope someone has an easy solution. Thanks In advance. Here is the error: E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.IllegalStateException: Could not find a method openSearch(View) in the activity class dk.mathias.splitcab.MainActivity for onClick handler on view class android.widget.Button with id 'btnStartSearch' MainActivity.java protected void onCreate

Android Navigation Drawer unable to setText in a Fragment from MainActivity

a 夏天 提交于 2019-12-29 09:39:07
问题 I am trying to put GPS coordinates on TextView of a Fragment from MainActivity but I can not figure out how to do this. I have: MainActivity.java LocationFragment.java I want to update an TextView in LocationFragment from MainActivity's onLocationChanged() method. Is any chance to do this : public void onLocationChanged(Location location) { lat = (double) (location.getLatitude()); lng = (double) (location.getLongitude()); fragment.updateText(lat +" "+lng); } 回答1: You can use Interface for it

Android - Calling an ordinary object method from an activity

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-29 09:24:07
问题 First, I am an android rookie, so my solution ways can be found awkward, and i am open to suggestions. I am trying to create a game manager object that handles all transitions between activities. And my purpose is that while in an activity, menuOut method will call the changeActivity method of GameManager object with nextActivity argument and changeActivity will start that Activity. I am getting errors consistently, and did not find a solution. Here is my source codes: GameManager: public

Error:Execution failed for task ':app:dexDebug'. > comcommand finished with non-zero exit value 2

心已入冬 提交于 2019-12-29 09:13:11
问题 In android studio I implement push notification. I downloaded a demo and import in android studio. There is no problem in source code but when I run this program it will show the problem: Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 2 How can I solve it?Please help! 回答1: You need to know the root

Start two services in foreground?

自作多情 提交于 2019-12-29 08:09:15
问题 In an effort to keep my services alive, can I have more than one service in foreground? I am starting two services at once, and I don't want any of them to be destroyed. So, after reading for hours, I found the solution is to return START_STICKY and use startForeground(...) on my service. But, I have two services, so can I have them both be in the foreground, and both never be destroyed? 回答1: There are several aspects to consider. First of all: if you have two services in foreground, you have

Send data from Activity to Fragment already created

不打扰是莪最后的温柔 提交于 2019-12-29 07:29:30
问题 I only have found information about how to create a Fragment sending some data to it, but only in its instantiation with the constructor. But I want to know if it is possible to send some data (for instance, two Double objects) to a Fragment from an Activity without having to create a new instance of the Fragment. A Fragment that has been previously created. 回答1: Just add a method in Fragment which you want to receive arguments, then invoke the method in Activity. Activity's Code: Fragment's

Android retain callback state after configuration change

三世轮回 提交于 2019-12-29 06:58:10
问题 I understand pretty well about Android lifecycle. I post here because I've observed one weird behavior, anyway this is my own thought. My case is like this: One activity will use a simple layout with just a single EditText . In the activity onCreate method, i set some default text to the EditText and in later part of the method, assign a TextWatcher to the EditText so whenever user types in anything, i can response in my own way. Everything is alright until I rotate the screen. The

Passing Integer Between Activities and Intents in Android Is Always Resulting in Zero / Null

笑着哭i 提交于 2019-12-29 04:55:05
问题 I'm attempting to pass two integers from my Main Page activity (a latitude and longitude) to a second activity that contains an instance of Google Maps that will place a marker at the lat and long provided. My conundrum is that when I retrieve the bundle in the Map_Page activity the integers I passed are always 0, which is the default when they are Null. Does anyone see anything glaringly wrong? I have the following stored in a button click OnClick method. Bundle dataBundle = new Bundle();

Why is my onResume being called twice?

醉酒当歌 提交于 2019-12-29 03:32:06
问题 Basically, this is what I'm doing 1) Set AlarmManager to execute BroadcastReceiver (BCR) Intent intent = new Intent(m_Context, BCR.class); intent.putExtras(extras); PendingIntent pendingIntent = PendingIntent.getBroadcast(m_Context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, StartTime, pendingIntent) 2) Start MyActivity from BCR @Override public void onReceive(Context context, Intent