Add a new activity to an existing project in Android Studio

Step 1: Firstly, right-click the app folder and select New > Activity  and choose your Activity as per requirement. Here I choose Login Activity as shown in figure below.

1

Step 2: After that Customize the Activity in Android Studio. Enter the “Activity Name”, “Layout Name”, “Title” ,”Hierarchical Parent”, “Package name”,”Source Language” and “Target Source Set ” in the Text box and Click on Finish button.

Note: Default configuration works fine.

All steps are shown in figure in below:

2

To configure Hierarchical parent click on right three doted  button. Here I choose MainActivity but you can choose as your requirement.

3

If you want to write program in kotlin click Source Language and set to kotlin. Default source language  is Java in android Studio 3.

4

5

To set Target Source Set click on target source set It will show three option.By default it set to main in android studio 3.

6

Step 3: After that your new Activity in Layout will be created. Your XML Code is in Text and your Design Output is in Design. See below figure.

7

 

Close, Save and Open Recent project in Android Studio

Open Project in Android Studio

Advertisements

Understanding PHP Generator With Example

phpgen

Overview Of Generators:

Generator does not returns a value but generates a sequence of values. It is a normal function that instead of returning a value yields as many values as needed to get a desired result.

A generator allows you to write code that uses foreach to iterate over a set of data without needing to build an array in memory, which may cause you to exceed a memory limit, or require a considerable amount of processing time to generate.

A generator function looks just like a normal function, except that instead of returning a value, a generator yields as many values as it needs to.

The heart of a generator function is the yield keyword. In its simplest form, a yield statement looks much like a return statement, except that instead of stopping execution of the function and returning, yield instead provides a value to the code looping over the generator and pauses execution of the generator function.

A Simple Generator:

<?php

function gen_one_to_ten(){

for($i=1;$i<=10;$i++){

yield$i;

}

}

$gen=gen_one_to_ten();

foreach($gen as $value){

echo"$value\t";

}

?>

Fibonacci Generator Example:

<?php

function fib($n)

{

$cur=1;

$prev=0;

for ($i=0; $i<$n; $i++) {

yield$cur;

$temp=$cur;

$cur=$prev+$cur;

$prev=$temp;

}

}

$fibs = fib(9);

foreach ($fibs as $fib) {

echo" ".$fib;

}

// prints: 1 1 2 3 5 8 13 21 34
?>

 

Close, Save and Open Recent project in Android Studio

When the project is already opened in android studio and the same time you want to open another project  in android studio then use the File>> Open Recent. When the project work is done in android studio to close  project use the File>>Close project and to save project in android studio  use the Save All option from the File>>Save All.

  Open Recent project in Android Studio:

Firstly, Click on File then Click on Open Recent and choose the file which file you want to be opened. I choose “MathGame” file.

1

After that a message box will be shown on your computer screen. This will show  project will be opened in “This Window” or “New Window”. I open the project in “This Window” and After that your project will be opened.

2

Close project in Android Studio:

To close project you need click ” File —> Close Project ” menu in top menu bar.

3

Save project in Android Studio:

To save project, you need to click ” File —> Save All ” menu in top menu bar or just click Ctrl+S.

4

To remove project completely from Android Studio, just to File->Close Project, then, in the “Welcome to Android Studio” window, you have an “x” right next to each project; just press it to remove it from the recents.

5

I hope you find this blog post very helpful while creating Android Project in Android Studio. Let me know in a comment if you have any questions regarding Android Studio. I will reply you ASAP.

 

 

Open Project in Android Studio

When a Android project is already present in your system then you can open it easily in Android Studio. Here we discuss several method  to open project in Android Studio.

Open Recent Project in Android Studio:

Firstly, open the Android Studio. You will see Welcome to Android Studio on your computer screen. You will also see it if you close your current project(s). After that we could open an existing android studio project in Android Studio from “Recent Projects” directly. Just click the file name in recent projects which you want to open.

1

Open Project Not Present In Recent Projects:

we could open an existing android studio project in Android Studio just clicking on “Open an existing Android Studio project”.

2

In the file dialog that appears, navigate into the project directory of the project. We located and selected “IndependenceDay” project and then Click OK.

3

From the file menu:

Click on File and then Click on Open.

g

To reopen other recent projects when a project is already opened in Android Studio. Go to File >> Open Recent >> Choose recent projects you want to open

6

I hope you find this blog post very helpful while creating Android Project in Android Studio. Let me know in a comment if you have any questions regarding Android Studio. I will reply you ASAP.

Create/Start New Project In Android Studio

Objective:

The main objective of this tutorial is how to create a new project in Android Studio. And this tutorial is for those who are new to Android Studio.

To create a new project perform the following steps:

Step 1: Start and configure the project:

Firstly, open the Android Studio. You will see “Welcome to Android Studio” on your computer screen. After that you click on “Start a new Android Studio project”.

ff

If you do have a project opened, click File > New > New Project.

aa

After that you will see “Create Android Project” on your computer screen. Here enter the “Application name” , the “Company Domain” ( Company domain is used to uniquely identify the App. So two App with same Application name will have different company domain. e.g. I used here “sanikamal.ruatech.com”)and the project location in the text box and then Click Next button. If you want to use C++ and/or Kotlin code in your project, check the corresponding checkboxes to set up your project accordingly. You can always add C++ code and add Kotlin code later.

ffg

Step 2: Select form factors and API level:

After that you will see “Target Android Devices” on your computer screen and select the form factors your app will be run on. Select “Phone and Tablet” field and enter the “Minimum SDK” in the text box and then Click Next button. When you select Minimum SDK, Android studio will give you some active android devices percentage that will support your android application. Otherwise, you can also click on “Help me choose” button for more information about android platform versions.

ggg

Step 3: Add an activity:

This screen suggests you “Add an Activity to Mobile” first. If you don’t want to add any activity at starting, you can select Add no activity option. We selected Empty Activity.

If you have selected Phone and Tablet in option in the last screen then it will display the only phone related suggestions.

For example, select Google Maps Activity for google map project, Login Activity for User Login project etc.

bbbbb

Step 4: Configure your activity:

Here, you can customize your selected activity. You can change your Activity name from here. Enter the “Activity Name” in the text box and enter the “Layout Name” in the text box and then Click Finish button.

Activity Name Name of JAVA file for programming

Layout Name Name of XML file for designing UI

swsw

Android Studio now sets up your project and opens the IDE.

fgggjh

I hope you find this blog post very helpful while creating Android Project in Android Studio. Let me know in a comment if you have any questions regarding Android Studio. I will reply you ASAP.

 

Android Studio Tutorial For Beginners

android-studio-logo-840x359.pngAndroid Studio Introduction

Android Studio is the official IDE (integrated development environment) for developing Android Apps by Google. It is purpose built for Android to accelerate your development and help you build the highest-quality apps for every Android device. It is based on  JetBrains’ IntelliJ IDEA software and has lots of amazing features which helps developer in creating Android App.

Android Studio is available for free download on Windows, Mac OS X and Linux.

Prerequisites For Learning Android Studio:

There are two prerequisites for learning Android Studio tips:

System Requirements:

First your system OS must be either Windows, Max OS X or Linux with below requirement:

Windows

  • Microsoft® Windows® 7/8/10 (32- or 64-bit)
  • 3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android Emulator
  • 2 GB of available disk space minimum,
    4 GB Recommended (500 MB for IDE + 1.5 GB for Android SDK and emulator system image)
  • 1280 x 800 minimum screen resolution

Mac

  • Mac® OS X® 10.10 (Yosemite) or higher, up to 10.13 (macOS High Sierra)
  • 3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android Emulator
  • 2 GB of available disk space minimum,
    4 GB Recommended (500 MB for IDE + 1.5 GB for Android SDK and emulator system image)
  • 1280 x 800 minimum screen resolution

Linux

  • GNOME or KDE desktopTested on Ubuntu® 14.04 LTS, Trusty Tahr (64-bit distribution capable of running 32-bit applications)
  • 64-bit distribution capable of running 32-bit applications
  • GNU C Library (glibc) 2.19 or later
  • 3 GB RAM minimum, 8 GB RAM recommended; plus 1 GB for the Android Emulator
  • 2 GB of available disk space minimum,
    4 GB Recommended (500 MB for IDE + 1.5 GB for Android SDK and emulator system image)
  • 1280 x 800 minimum screen resolution

 

 

Android Studio:

The second thing you need is to download Android Studio on your system and install it. It is available for free download on Windows, Mac OS X and Linux OS.


Eclipse Vs Android Studio

Android App Development is mostly done in two IDE i.e. Eclipse and Android Studio. Earlier Eclipse was the popular IDE but now Android Studio has taken over it. This is because Google has ended the support for Eclipse and now only focused on Android Studio. Google also recommended developer to import their Android projects into Android studio and use Android Studio.

Android Studio Tutorials For Beginners:

Below are the tutorials links on Android Studio:

  • Create New Project – Learn how to start/create a new project in Android Studio
  • Open Project – Learn how to open projects in Android Studio.
  • Close, Save and Open Recent Project – Learn more about how to open saved projects and close current project in Android Studio.
  • Create New Activity – Learn to create New Activity in Android Studio .
  • Create New Java Class -Learn how to create New Java Class in Android Studio.
  • Create Virtual Device – Learn how to create a new AVD  in Emulator.
  • Run App in Emulator – Learn how to run and test Android App in Emulator.
  • Run/Test App in Real Device – Learn how to run app in real device.
  • Create Drawable Resource XML File – Learn how to create drawable resource XML file in Android Studio.
  • Add/Create Landscape Layout – Learn to design app in Landscape orientation in Android Studio.
  • Create Local HTML File – Learn how to create local HTML file in Android Studio.
  • Create Raw Folder – Learn how to create Raw Folder in Android Studio.
  • Add/Create Assets Folder – Learn how to create Assets folder in Android Studio.
  • Install Genymotion Emulator – Howt to install Genymotion Emulator in Android Studio.
  • Import/Add External JAR File – Learn how to import an External JAR file to Android Studio.
  • Change API SDK Level – Learn how to change the SDK level of API in Android Studio.
  • Create/Add New Package Inside Src Folder – Learn how creating new package inside Src Folder in Android Studio.
  • Creating Folders for Adding Different Resolution Images – Learn how add folder for adding images with different resolution in Android Studio.
  • Create An Interface – Learn how to create Interface in Android Studio.
  • Add Image to Drawable Folder in Android Studio – Learn Steps to add image to Drawable Folder in Android Studio.
  • Change Icon Of Your Android App – Learn how to change the android app icon in Android Studio.
  • Add Audio To Android App – How to  add audio to your Android application.
  • Application Launcher Icon Size – Learn about different application launcher icon sizes in android studio.
  • Basic Activity In Android Studio –Learn about how to create a basic activity in android studio.
  • Implement Abstract Method – Learn about how to implement abstract methods on clicks or using shortcuts in android studio.
  • Change Package Name In Android Studio – How to rename/change package name in Android Studio
  • Generate Signed Apk In Android Studio For Publishing & Updating Application.
  • How To Publish Android App On PlayStore – Learn how to publish your first Android App on Play store.
  • How To Create Anim Folder & Animation File In Android Studio –Steps to create an anim folder in Android Studio to store animation file under the resource folder of our application.

PHP7 Arithmetic Operators

PHP Arithmetic Operators

The PHP arithmetic operators are used with numeric values to perform common
arithmetical operations, such as addition, subtraction, multiplication etc.
+   Addition     $x + $y     Sum of $x and $y
–   Subtraction     $x – $y     Difference of $x and $y
*   Multiplication  $x * $y     Product of $x and $y
/   Division     $x / $y     Quotient of $x and $y
%   Modulus      $x % $y     Remainder of $x divided by $y
**  Exponentiation  $x ** $y    Result of raising $x to the $y’th power

PHP Increment / Decrement Operators

The PHP increment operators are used to increment a variable’s value.
The PHP decrement operators are used to decrement a variable’s value.
++$x    Pre-increment   Increments $x by one, then returns $x
$x++    Post-increment  Returns $x, then increments $x by one
–$x    Pre-decrement   Decrements $x by one, then returns $x
$x–    Post-decrement  Returns $x, then decrements $x by one
<?php

$x=20;

$y=15;

//addition

$add=$x+$y;

echo $add.'
'; //subtraction $sub=$x-$y; echo $sub.'
'; //multiplication $mult=$x*$y; echo $mult.'
'; //division $div=$x/$y; echo $div.'
'; //modulus $mod=$x%$y; echo $mod.'
'; //Exponentiation $exp=$x**$y; echo $exp.'
'; $num=20; $num2=10; //Pre-increment echo ++$num.'
'; //post-increment echo $num++.'
'; echo $num.'
'; //Pre-decrement echo --$num2.'
'; //Post-decrement echo $num2--.'
'; echo $num2.'
'; ?>

Download File

PHP 7 Comparison Operator

PHP Comparison Operators
The PHP comparison operators are used to compare two values (number or string):
==       Equal    $num1 == $num2    Returns true if $num1 is equal to $num2
===    Identical    $num1 === $num2   Returns true if $num1 is equal to $num2, and they are of the same type
!=       Not equal    $num1 != $num2    Returns true if $num1 is not equal to $num2
<>       Not equal    $num1 <> $num2    Returns true if $num1 is not equal to $num2
!==     Not identical    $num1 !== $num2   Returns true if $num1 is not equal to $num2, or they are not of the    same type
>         Greater than     $num1 > $num2     Returns true if $num1 is greater than $num2
<        Less than    $num1 < $num2     Returns true if $num1 is less than $num2
>=     Greater than or equal to $num1 >= $num2   Returns true if $num2 is greater than or equal to $num2
<=     Less than or equal to    $num1<= $num2    Returns true if $num2 is less than or equal to $num2
<?php

$num1=10;

$num2=7;

$numStr='10';

//always true

if(true){

echo'I am always true'.'<br>';

}

//always false

if(false){

echo'I am true'.'<br>';

}else{

echo'I am always false'.'<br>';

}

//return true if $num1 is equal to $numStr

if($num1==$numStr){

echo'we are same'.'<br>';

}

//return true if $num1 is identical to $numStr and same type

if($num1===$numStr){

echo'we are identical'.'<br>';

}else{

echo 'We are not identical'.'<br>';

}

//return true if $num1 is not equal to $num2

if($num1!=$num2){

echo'we are not same'.'<br>';

}

// same as !=

if($num1<>$num2){

echo'we are not same'.'<br>';

}

if($num1!==$numStr){

echo'we are not identical'.'<br>';

}

//return true if $num1 is greater than $num2

if($num1>$num2){

echo$num1.' is greater than '.$num2.'<br>';

}else{

echo$num2.' is greater than '.$num1.'<br>';

}

//return true if $num1 is less than $num2

if($num1<$num2){

echo$num1.' is less than '.$num2.'<br>';

}else{

echo$num2.' is less than '.$num1.'<br>';

}

//return true if $num1 is greater than or equal to $num2

if($num1>=$num2){

echo$num1.' is greater than or equal to'.$num2.'<br>';

}else{

echo$num2.' is greater than or equal to'.$num1.'<br>';

}

//return true if $num1 is less than or equal to $num2

if($num1<$num2){

echo$num1.' is less than or equal to '.$num2.'<br>';

}else{

echo$num2.' is less than or equal to '.$num1.'<br>';

}

?>

Download file

PHP Class Attribute With Example

An attribute is known as data members and is used to hold data of a class. The data that it holds are specific to the nature of the class in which it has been defined. For example, a Book class would hold data related to a book, an Publisher class would hold data related a an publisher. Properties can accept values like strings, integers, and booleans (true/false values), like any other variable. Within class methods non-static properties may be accessed by using -> (Object Operator): $this->property (where property is the name of the property). Static properties are accessed by using the :: (Double Colon): self::$property. Attributes can either be public, private or protected – the default being public. These are called Access Specifiers.
Example Code:

class Book {
private $book_name, $author_name;
private $price = 0;
public function getData($book_name, $author_name) {
$this->book_name = $book_name;
$this->author_name = $author_name;
}public function printData() {
echo 'Book Name:'.$this->book_name . 'Author Name:' . $this->author_name;
}
}
$c1 = new Book();

In the above example $book_name, $author_name and $price are data members or attributes of the class Book. Of these attributes, $price has a default value of zero assigned to it. This means that when an object of the Book class has been created, $book_name and $author_name will be blank whereas; $price will be initialized with default value of zero.

php-magic-constants
c-program-to-find-simple-interest