Tuesday, 27 February 2018

Activity LifeCycle

➤onCreate() — Called when the activity is first created
 ➤onStart() — Called when the activity becomes visible to the user
 ➤onResume() — Called when the activity starts interacting with the user
➤onPause() — Called when the current activity is being paused and the previous activity is being resumed
➤onStop() — Called when the activity is no longer visible to the user
➤onDestroy() — Called before the activity is destroyed by the system (either manually or by the system to conserve memory)
➤onRestart() — Called when the activity has been stopped and is restarting again

onclick of home btn which method called?
onpause onSaveInstanceState and onstop and then onresume
Restart the app after pressing home
onRestart
onStart
onResume


on backpressed?
onPause
onStop
onDestroy
onSaveInstanceState was not called, because there is no current state to resume – when you re-enter you will be back at the beginning
Restart the app after pressing back
onCreate
onStart
onResume

Turn off with the power button
onSaveInstanceState
onPause
 
When the phone was suspended, onSaveInstanceState and onPause were called in different orders, and onStop was called in some cases.
Turn on with the power button
onResume

from one activity to other-
when onrestart is called?
go from act1 to act 2 and when you come back from act2 to act1 on restart-- onstart--on resume is called

 

Friday, 16 February 2018

Android how to Clear App Data Programatically

public class MainActivity extends AppCompatActivity {

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//clearApplicationData();  ---Method 1
/* ((ActivityManager)MainActivity.this.getSystemService(ACTIVITY_SERVICE)) .clearApplicationUserData();*/ --- Method 2 // deleteAppData(); ---- Method 3
}

private void deleteAppData() {
try {
// clearing app data String packageName = getApplicationContext().getPackageName();
Runtime runtime = Runtime.getRuntime();
runtime.exec("pm clear "+packageName);

} catch (Exception e) {
e.printStackTrace();
} }


public void clearApplicationData() {
File cacheDirectory = getCacheDir();
File applicationDirectory = new File(cacheDirectory.getParent());
if (applicationDirectory.exists()) {
String[] fileNames = applicationDirectory.list();
for (String fileName : fileNames) {
if (!fileName.equals("lib")) {
deleteFile(new File(applicationDirectory, fileName));
}
}
}
}


public static boolean deleteFile(File file) {
boolean deletedAll = true;
if (file != null) {
if (file.isDirectory()) {
String[] children = file.list();
for (int i = 0; i < children.length; i++) {
deletedAll = deleteFile(new File(file, children[i])) && deletedAll;
}
} else {
deletedAll = file.delete();
}
}

return deletedAll;
}

}

Wednesday, 14 February 2018

Espresso Check for the Youtube URL



//Using Espresso Intent to check whether the appropriate URL is openedIntents.init();
Matcher<Intent> expectedIntent = allOf(hasAction(Intent.ACTION_VIEW), hasData("req_url"));
intending(expectedIntent).respondWith(new Instrumentation.ActivityResult(0, null));
onView(withText(startsWith("Video"))).perform(click());
intended(expectedIntent);
Intents.release();

Add this dependency in build.gradle
androidTestCompile 'com.android.support.test.espresso:espresso-intents:3.0.1'

Start and Send data to Activity from ADB

1)Navigate to platform-tools which is inside sdk android
2)Then type adb shell am start -n yourpackagename/.activityname
3)Starts the Activity
4)To send the data
adb shell am start -n yourpackagename/.activityname -e myKey test
5)You can retrieve from App Side
getIntent().getStringExtra("myKey")
6)Done

Friday, 2 February 2018

Nexus not detecting in android studio

1.Update Android SDK (Google USB Driver)

2.From PC Control Panel, System -> Device manager -> Right click Nexus 4 -> Update driver.

3.Set android-sdk-folder\extras\google\usb_driver as path to search, include subfolders checked.

If windows tells you that the driver is up to date, just uninstall the driver (right click on nexu4 -> uninstall driver) and start from step 2 again.
After that, open a cmd and type adb kill-server and then a adb devices, now it will include your device.


More details
https://stackoverflow.com/questions/20343014/adb-doesnt-show-nexus-5-device

Git in Android Studio

How to get all changes of release branch to developer branch?


1)Navigate to VCS-->Git--->Merge Changes
There make sure you are on your current branch
2)Branvhes to merge:select the appropriate branch which you want to incorporate
3)Commit
4)Push

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...