Skip to content

Instantly share code, notes, and snippets.

@ckurtm
Created November 2, 2015 06:18
Show Gist options
  • Save ckurtm/ea4ba85c1dfc7be4a43b to your computer and use it in GitHub Desktop.
Save ckurtm/ea4ba85c1dfc7be4a43b to your computer and use it in GitHub Desktop.

Revisions

  1. ckurtm created this gist Nov 2, 2015.
    26 changes: 26 additions & 0 deletions AndroidManifest.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.peirr.test">

    <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme">

    <receiver
    android:name=".MyReceiver"
    android:enabled="true"
    android:exported="true" />

    <service
    android:name=".MyService"
    android:enabled="true"
    android:exported="true" />

    <activity android:name=".MyActivity"
    android:exported="true"
    />
    </application>

    </manifest>
    27 changes: 27 additions & 0 deletions MyActivity.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    package com.peirr.test;

    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.TextView;

    public class MyActivity extends AppCompatActivity {

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

    TextView lname = (TextView) findViewById(R.id.name);
    TextView lage = (TextView) findViewById(R.id.age);
    Intent intent = getIntent();
    if (intent != null) {
    String name = intent.getStringExtra("name");
    int age = intent.getIntExtra("age",0);

    lname.setText(name);
    lage.setText(String.valueOf(age));

    }
    }
    }
    19 changes: 19 additions & 0 deletions MyReceiver.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    package com.peirr.test;

    import android.content.BroadcastReceiver;
    import android.content.Context;
    import android.content.Intent;
    import android.widget.Toast;

    public class MyReceiver extends BroadcastReceiver {
    public MyReceiver() {}

    @Override
    public void onReceive(Context context, Intent intent) {
    if (intent != null) {
    String name = intent.getStringExtra("name");
    int age = intent.getIntExtra("age",0);
    Toast.makeText(context,"MyReceiver Received: [name:"+name+"] [age:"+age+"]",Toast.LENGTH_SHORT).show();
    }
    }
    }
    27 changes: 27 additions & 0 deletions MyService.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    package com.peirr.test;

    import android.app.Service;
    import android.content.Intent;
    import android.os.IBinder;
    import android.widget.Toast;

    public class MyService extends Service {

    public MyService() {}

    @Override
    public IBinder onBind(Intent intent) {
    // TODO: Return the communication channel to the service.
    throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
    if (intent != null) {
    String name = intent.getStringExtra("name");
    int age = intent.getIntExtra("age",0);
    Toast.makeText(this, "MyService Received: [name:" + name + "] [age:" + age + "]", Toast.LENGTH_SHORT).show();
    }
    return super.onStartCommand(intent, flags, startId);
    }
    }