Search..

Sunday, March 31, 2024

How to check backStack of Fragment that it is already assisted with Activity



public void checkBackStackAlreadyPresent()
{

 int fragmentCount = getSupportFragmentManager().getBackStackEntryCount();

if (fragmentCount != 0) {
if (getSupportFragmentManager().getBackStackEntryAt(fragmentCount - 1).getName().equals("LocationSearch")) {
getSupportFragmentManager().popBackStack();
} else {
clearStack();
}
}

}



public void addFragment(){

//flightDatePickerFragment = null;
FragmentTransaction fragmentTransaction = getSupportFragmentManager()
.beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_in_bottom,
R.anim.slide_up_from_bottom);
fragmentTransaction.replace(R.id.secondarycontent_frame,
locationSearchFragment);
fragmentTransaction.addToBackStack("LocationSearch");
fragmentTransaction.commit();

}

Wednesday, January 3, 2024

How to check from where your app is downloaded

 public static boolean verifyInstallerId(Context context) {

// A list with valid installers package name
List<String> validInstallers = new ArrayList<>(Arrays.asList("com.android.vending", "com.google.android.feedback"));

// The package name of the app that has installed your app
final String installer = context.getPackageManager().getInstallerPackageName(context.getPackageName());

// true if your app has been downloaded from Play Store
return installer != null && validInstallers.contains(installer);
}

Sunday, December 31, 2023

How to load json from asset file in android

 fun loadAssetFromFile(context: Context)

{
val inputStram:InputStream=context.assets.open("jokes.json")
val size=inputStram.available()
val buffer=ByteArray(size)
inputStram.read(buffer)
inputStram.close()
val json= String(buffer,Charsets.UTF_8)
data=Gson().fromJson(json,Array<Jokes>::class.java)
isDataLoading.value=true
}

Monday, December 25, 2023

Jetpack composable Navigation

 Q :-   what is Navigation component 

          in jetpack compose  navigate between two  composable function.


      * NavHost :- It is area where compose screen will be render.

       * NavGraph :- It is tells us where should be go from one screen to another

           Like - If you have multiple screen like registration and login,forget password

            then we should go registration screen to either login or forget passsword screen.


       * NavController :- whatever interation has been done between using navHost and NavGraph

          that can manage by NavController and its also manage the  backstack.





            Example :- 


         




              

Sunday, December 24, 2023

Composable basic

  Q1 :- what is Box 

 Ans : -> Its like a  a framLayout 

Q2 :- what is  FillMaxSize 

   Ans :- To cover whole height and width.

 Q 3:- what is Clip Modifier 

            It is used to to pass the custom safe for view.


Q 4:-   What is Produce State  ?   

         Produce state  is upadate the  object asynchronous and give the object .

         its utility function of jetpack compose.

       Example :-

          @Composable

fun StateProducerExample() {

var counter by produceState(initialValue = 0) {
// This block is executed in a coroutine
while (true) {
delay(1000) // Simulate some asynchronous work
counter++ // Update the counter
}
}

Column {
Text("Counter value: $counter")
}
}


Q 5:-   What is derivedState State  ?   

           if you have multiple state object you want to make another new state object using

          both . on that you can use derivedStateOf .

            Example :-  

           @Composable

fun DerivedStateOfExample() { var name by remember { mutableStateOf("John") } var age by remember { mutableStateOf(25) } // Using derivedStateOf to create a derived state based on name and age val formattedText by derivedStateOf { "Name: $name, Age: $age" } Column { // UI elements using the derived state Text("Formatted Text: $formattedText") // UI elements for updating the base states TextField(value = name, onValueChange = { name = it }, label = { Text("Name") }) TextField(value = age.toString(), onValueChange = { age = it.toIntOrNull() ?: 0 }, label = { Text("Age") }) } }












Saturday, October 28, 2023

How to lunch another app by scheme

 private fun TestLunch() {

    try {
val dataString="natives://"+"com.photovideo.camera"
val intent=Intent()
intent.addCategory(Intent.CATEGORY_DEFAULT)
intent.addCategory(Intent.CATEGORY_BROWSABLE)
intent.setData(Uri.parse(dataString))
startActivity(intent)
// startActivity(packageManager.getLaunchIntentForPackage("com.photovideo.camera"))
} catch (e: PackageManager.NameNotFoundException) {
startActivity(Intent(Intent.ACTION_VIEW).setData(Uri.parse("https://play.google.com/store/apps/details?id=" + "com.google.android.youtube")))
}
}