slow startup (500ms) with all apps made by My Android studio - android

I'm a beginner and when i ever i make an app and i test it on real phone
the first activity takes 400-900ms to start, even when it's only show a text view or a button. (just empty App)
on the same phone i have few apps (Games) from Play Store , and they work instantly! there's no 10ms delay!
so I'm wondering why is this happening to me even if i make (Empty App)
I mean seriously, why would it starts slowly with this simple code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button);
button.setText("Hello World");
}
}

The problem is that the APK you are generating is with debug property on, so this APK is considered to be in development mode that's why it will take longer to launch. You need to generate a production APK (same one you can publish on Play Store) in order to have the same launch speed as the other apps. Check this out : Sign Your APK

Related

My Android App hangs on SharedPreferences, but only in Android 5

An odd one here. I've built an app in Android Studio which is working perfectly in Android 4 (4.4.2), but it just stopping on Android 5.0.2. It's not throwing up any errors, just stopping.
Going line by line, it seems to be focussed on the SharedPreferences file, which it's not loading.
protected void onCreate(Bundle savedInstanceState) {
try {
super.onCreate(savedInstanceState);
final SharedPreferences sharedPreferences = this.getSharedPreferences("appname", MODE_PRIVATE );
currentlyTracking = sharedPreferences.getBoolean("currentlyTracking", false);
So, on Android 4, going line by line, when I get to the currentlytracking line, I can view the contents of the SharedPreferences file in the Variables window, and the app works. On Android 5, when I get to the currentlytracking line, none of the variables show up, and it just says 'Collecting data'. The app then stops if I try to continue on.
Interestingly, if I change the name of the Sharedpreferences file, it will create a new file but then fail to save to it.
This is only happening on Android 5, any thoughts would be appreciated.
Cheers

"...cannot be resolved to type" error message; no method suggestions in Eclipse

Ok guys I've got a question that for the life of me I cannot get figured out. I'm using Eclipse, and I've got the Android ADT pluging all installed, the program configured with the Android SDK path, and all the extra SDK parts downloaded (Google API's, SDK Platforms, System Images). Here is my problem: whenever I go to access a method from a certain object, Eclipse gives no method "suggestions" like it usually does. I'm probably not explaining this the best, so I've attached a screenshot that kind of illustrates the issue.
public class StartingPoint extends Activity {
int counter;
Button add;
Button sub;
TextView display;
//putting add.whatever here doesn't work
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_starting_point);
counter = 0;
add = (Button) findViewById(R.id.buttonAdd);
sub = (Button) findViewById(R.id.buttonSub);
display = (TextView) findViewById(R.id.textView1);
add.setOnClickListener(new View.OnClickListener() {
//putting add.whatever here doesn't show suggestions either.
I've tried everything I can think of to get it working, deleting & reinstalling eclipse, deleting everything Android from with Eclipse and going through all the SDK setup again, changing my workspace, creating an entirely new project, deleting the Eclipse preference file, endless Googling, resetting & altering settings, and I can't for the life of me figure out what's causing this. Any ideas? Thanks!

Facebook android scrumptious tutorial ListView not clickable on Google TV

I have just recently built an android tablet app (looking to port it to Google TV now) which is in close analogy to the Facebook Android Scrumptious App tutorial. In particular the issue is in the section of "Show Friends" of that tutorial: http://developers.facebook.com/docs/tutorials/androidsdk/3.0/scrumptious/show-friends/
On the tablet when I touch the Select a Friend part of the ListView, it responds to the onClick. But on the Google TV using Dpad remote, this doesn't work. In particular, (after doing some Log) the onClick never gets called. I have written the part of the code from the tutorial where the onClick doesn't get called.
Just to summarize: This onClick DOES GET CALLED on android tablet and mobile. BUT DOES NOT GET CALLED when on Google TV and clicking using the Enter button on the remote control.
Any help on getting this onClick to get called on the Google TV platform would be most helpful.
private class PeopleListElement extends BaseListElement {
public PeopleListElement(int requestCode) {
super(getActivity().getResources().getDrawable(R.drawable.action_people),
getActivity().getResources().getString(R.string.action_people),
getActivity().getResources().getString(R.string.action_people_default),
requestCode);
}
#Override
protected View.OnClickListener getOnClickListener() {
return new View.OnClickListener() {
#Override
public void onClick(View view) {
// Supposed to do something here BUT ON GOOGLE TV DOES NOT GET CALLED
}
};
}
what happens when you use the touchpad pointer to click the item? I suspect that it may be related to the layout hierarchy and that something higher up is grabbing the dpad event. Conversely it could be that dpad focus is not on the element you think it is.
There are some bugs amongst the various Google TV devices not sending the right key codes for things like OK/Enter or the D-pad center. You might want to add a key listener to see what codes are getting sent to your view.

Creating a Questionnaire in Android

Peace be on all of you!
I have to develop a questionnaire like small android app. There will be 10 questions with only 2 types of answers, i.e. either "Yes" or "No". When the user will answer all of the 10 questions, a report will be shown to user according to his answers.
Kindly tell me, how should I proceed? Do I need to use database (sqlite) or can work without it? and how should I start to develop this app?
I am new to Android.
Thank-you!
If you are new to Android, than use a web approach: Show a html page 1-10 in a webView and link it each other and finally the 10th is linked to an url, where you will do a http POST / GET with your collected 10 params. Exactly as how would you do in a "standard' web development. Also you can use several app to wrapp into Android app: Appcelerator, Phonegap and so on.
Here is a class which is a screen: (Android Activity)
public class Help extends Activity{
private WebView webViewHelp;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.help);
webViewHelp = (WebView) findViewById(R.id.webViewHelp);
webViewHelp.loadUrl("file:///android_asset/ui/help.html");
}
}
you need the help.xml build and placed into /res/layout/ folder.
Also write the help.html and place it into: /assets/ui folder and not android_asset and at is not file:///assets/ui/help.html!
in this case you have the starting point set up, than go and load with html links the next next next ... until is done, than pust url.
Somewhat easyer if you are doing in android ui development, and not web-like, but that need a bit more experience

How to write a test case method using Robotium in Android

I am writing a test case class for one of the activity in my application.
That Activity class contains license checking for the application in android market and also displays the splash screen for 3 seconds. Here I would like to test that activity is displaying the splash screen and checking the license using Robotium instrumentation in Android.
So please tell me how to do this.
To test that your splash screen is shown, you can try this, if you have set up robotium in your setup method, and named it solo:
public void testSplash() {
assertNotNull(solo.getCurrentActivity().findViewById( "the id of the splash" ));
}
public void testLicense() {
String licence = "my licence";
assertEquals(licence, (MyActivity) solo.getCurrentActivity().getLicence());
}

Categories

Resources