Skip to content

Instantly share code, notes, and snippets.

View AkaashSaini's full-sized avatar
🏠
Working from home

Akash Saini AkaashSaini

🏠
Working from home
  • searce
  • rajkot,GJ
View GitHub Profile
Pre-defined Functions
String functions
The string is represent by
“ABC”
or
‘ABC’
Functions –
a. strlen($str) – it returns the length of string.
<?php
Recycle View
It allocates memory for only those elements which are visible on screen. On scroll of screen it automatically refreshes the memory.
Step 1
Add Dependency for RecyclerView to gradle file
It already exists
implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
add this line using the version of above line
Fetching data from Table
Step 1 - Create following table in database android
Student(name,branch,roll)
Insert some records
Step 2 – Create PHP file to select data (show_students.php)
<?php
$cn=mysqli_connect("localhost","root","","android");
if(!$cn)
{
SharedPrefereces 
It is used to maintain parameters and values. These parameters can be used by any activity of application. So it can be used to pass parameters and there values from one activity to other.
Create editor from shared preferences.
SharedPreferences sp = getSharedPreferences("mypref", MODE_PRIVATE);
Editor editor=sp.edit()
Put some parameters
editor.clear();
editor.putString("name", "Elena"); // first is parameter and second is value
editor.putInt("idName", 12);
editor.commit();
Confirm Dialog
We can use Confirm Dialog of JavaScript in PHP. It is very useful when we try to perform sensitive data operation. Using it we can confirm before do operation on data like delete operation on data.
Example 1
<form
method="post"
action="delete_record.php"
onSubmit="return confirm('Do you want to delete?')">
<input type="submit" name="B1" value="Delete" />
</form>
Using Password Encryption
The general function md5() is used to create hash key of string. It takes the string input and produces 128 bit fingerprint.
To insert in database using following code
$email=$_POST["T1"];
$password=$_POST["T2"];
require_once("MyLib.php");
$pass=md5($password);
//echo $pass; die();
$sql="insert into logindata values('$email','$pass')";
Volley – Fetch Data as JSON
• Create following PHP script
<?php
$cn=mysqli_connect("localhost","root","","android");
if(!$cn)
{
echo "Unable to connect";
die();
}
Volley – Save Data
Volley is an HTTP library that makes networking for Android apps easier and most importantly, faster. It was developed by google and introduced in 2013. It is available as AOSP (Android Open Source Repository)
Volley is available on GitHub.
Volley offers the following benefits:
• Automatic scheduling of network requests.
• Multiple concurrent network connections.
• Transparent disk and memory response caching with standard HTTP cache coherence.
• Support for request prioritization.
• Cancellation request API. You can cancel a single request, or you can set blocks or scopes of requests to cancel.
• Ease of customization, for example, for retry and backoff.
activity_main.xml
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click the button to go to pip mode!"
android:textColor="@color/black"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"